blob: 58d690393b294b3f2b71ef6a004b14819dfe5b91 [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>
Shashank Sharma15953632017-03-13 16:54:03 +053037#include <drm/drm_scdc_helper.h>
Eric Anholt7d573822009-01-02 13:33:00 -080038#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010039#include <drm/i915_drm.h>
Jerome Anand46d196e2017-01-25 04:27:50 +053040#include <drm/intel_lpe_audio.h>
Eric Anholt7d573822009-01-02 13:33:00 -080041#include "i915_drv.h"
42
Paulo Zanoni30add222012-10-26 19:05:45 -020043static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
44{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020045 return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
Paulo Zanoni30add222012-10-26 19:05:45 -020046}
47
Daniel Vetterafba0182012-06-12 16:36:45 +020048static void
49assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
50{
Paulo Zanoni30add222012-10-26 19:05:45 -020051 struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
Chris Wilsonfac5e232016-07-04 11:34:36 +010052 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterafba0182012-06-12 16:36:45 +020053 uint32_t enabled_bits;
54
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010055 enabled_bits = HAS_DDI(dev_priv) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
Daniel Vetterafba0182012-06-12 16:36:45 +020056
Paulo Zanonib242b7f2013-02-18 19:00:26 -030057 WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits,
Daniel Vetterafba0182012-06-12 16:36:45 +020058 "HDMI port enabled, expecting disabled\n");
59}
60
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -030061struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
Chris Wilsonea5b2132010-08-04 13:50:23 +010062{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020063 struct intel_digital_port *intel_dig_port =
64 container_of(encoder, struct intel_digital_port, base.base);
65 return &intel_dig_port->hdmi;
Chris Wilsonea5b2132010-08-04 13:50:23 +010066}
67
Chris Wilsondf0e9242010-09-09 16:20:55 +010068static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
69{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020070 return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +010071}
72
Damien Lespiau178f7362013-08-06 20:32:18 +010073static u32 g4x_infoframe_index(enum hdmi_infoframe_type type)
David Härdeman3c17fe42010-09-24 21:44:32 +020074{
Damien Lespiau178f7362013-08-06 20:32:18 +010075 switch (type) {
76 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030077 return VIDEO_DIP_SELECT_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010078 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030079 return VIDEO_DIP_SELECT_SPD;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +010080 case HDMI_INFOFRAME_TYPE_VENDOR:
81 return VIDEO_DIP_SELECT_VENDOR;
Jesse Barnes45187ac2011-08-03 09:22:55 -070082 default:
Ville Syrjäläffc85da2015-12-16 18:10:00 +020083 MISSING_CASE(type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030084 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070085 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070086}
87
Damien Lespiau178f7362013-08-06 20:32:18 +010088static u32 g4x_infoframe_enable(enum hdmi_infoframe_type type)
Jesse Barnes45187ac2011-08-03 09:22:55 -070089{
Damien Lespiau178f7362013-08-06 20:32:18 +010090 switch (type) {
91 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030092 return VIDEO_DIP_ENABLE_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010093 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030094 return VIDEO_DIP_ENABLE_SPD;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +010095 case HDMI_INFOFRAME_TYPE_VENDOR:
96 return VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030097 default:
Ville Syrjäläffc85da2015-12-16 18:10:00 +020098 MISSING_CASE(type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030099 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300100 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300101}
102
Damien Lespiau178f7362013-08-06 20:32:18 +0100103static u32 hsw_infoframe_enable(enum hdmi_infoframe_type type)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300104{
Damien Lespiau178f7362013-08-06 20:32:18 +0100105 switch (type) {
106 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300107 return VIDEO_DIP_ENABLE_AVI_HSW;
Damien Lespiau178f7362013-08-06 20:32:18 +0100108 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300109 return VIDEO_DIP_ENABLE_SPD_HSW;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100110 case HDMI_INFOFRAME_TYPE_VENDOR:
111 return VIDEO_DIP_ENABLE_VS_HSW;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300112 default:
Ville Syrjäläffc85da2015-12-16 18:10:00 +0200113 MISSING_CASE(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300114 return 0;
115 }
116}
117
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200118static i915_reg_t
119hsw_dip_data_reg(struct drm_i915_private *dev_priv,
120 enum transcoder cpu_transcoder,
121 enum hdmi_infoframe_type type,
122 int i)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300123{
Damien Lespiau178f7362013-08-06 20:32:18 +0100124 switch (type) {
125 case HDMI_INFOFRAME_TYPE_AVI:
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300126 return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder, i);
Damien Lespiau178f7362013-08-06 20:32:18 +0100127 case HDMI_INFOFRAME_TYPE_SPD:
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300128 return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder, i);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100129 case HDMI_INFOFRAME_TYPE_VENDOR:
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300130 return HSW_TVIDEO_DIP_VS_DATA(cpu_transcoder, i);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300131 default:
Ville Syrjäläffc85da2015-12-16 18:10:00 +0200132 MISSING_CASE(type);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200133 return INVALID_MMIO_REG;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300134 }
135}
136
Daniel Vettera3da1df2012-05-08 15:19:06 +0200137static void g4x_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100138 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100139 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200140 const void *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700141{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200142 const uint32_t *data = frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200143 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100144 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300145 u32 val = I915_READ(VIDEO_DIP_CTL);
Damien Lespiau178f7362013-08-06 20:32:18 +0100146 int i;
David Härdeman3c17fe42010-09-24 21:44:32 +0200147
Paulo Zanoni822974a2012-05-28 16:42:51 -0300148 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
149
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300150 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100151 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700152
Damien Lespiau178f7362013-08-06 20:32:18 +0100153 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300154
155 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700156
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300157 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700158 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200159 I915_WRITE(VIDEO_DIP_DATA, *data);
160 data++;
161 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300162 /* Write every possible data byte to force correct ECC calculation. */
163 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
164 I915_WRITE(VIDEO_DIP_DATA, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300165 mmiowb();
David Härdeman3c17fe42010-09-24 21:44:32 +0200166
Damien Lespiau178f7362013-08-06 20:32:18 +0100167 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300168 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200169 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700170
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300171 I915_WRITE(VIDEO_DIP_CTL, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300172 POSTING_READ(VIDEO_DIP_CTL);
David Härdeman3c17fe42010-09-24 21:44:32 +0200173}
174
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200175static bool g4x_infoframe_enabled(struct drm_encoder *encoder,
176 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800177{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200178 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Jesse Barnes89a35ec2014-11-20 13:24:13 -0800179 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Jesse Barnese43823e2014-11-05 14:26:08 -0800180 u32 val = I915_READ(VIDEO_DIP_CTL);
181
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300182 if ((val & VIDEO_DIP_ENABLE) == 0)
183 return false;
Jesse Barnes89a35ec2014-11-20 13:24:13 -0800184
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300185 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
186 return false;
187
188 return val & (VIDEO_DIP_ENABLE_AVI |
189 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
Jesse Barnese43823e2014-11-05 14:26:08 -0800190}
191
Paulo Zanonifdf12502012-05-04 17:18:24 -0300192static void ibx_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100193 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100194 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200195 const void *frame, ssize_t len)
Paulo Zanonifdf12502012-05-04 17:18:24 -0300196{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200197 const uint32_t *data = frame;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300198 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100199 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100200 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200201 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300202 u32 val = I915_READ(reg);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200203 int i;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300204
Paulo Zanoni822974a2012-05-28 16:42:51 -0300205 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
206
Paulo Zanonifdf12502012-05-04 17:18:24 -0300207 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100208 val |= g4x_infoframe_index(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300209
Damien Lespiau178f7362013-08-06 20:32:18 +0100210 val &= ~g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300211
212 I915_WRITE(reg, val);
213
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300214 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300215 for (i = 0; i < len; i += 4) {
216 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
217 data++;
218 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300219 /* Write every possible data byte to force correct ECC calculation. */
220 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
221 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300222 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300223
Damien Lespiau178f7362013-08-06 20:32:18 +0100224 val |= g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300225 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200226 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300227
228 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300229 POSTING_READ(reg);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300230}
231
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200232static bool ibx_infoframe_enabled(struct drm_encoder *encoder,
233 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800234{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200235 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Jani Nikula052f62f2015-04-29 15:30:07 +0300236 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200237 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
238 i915_reg_t reg = TVIDEO_DIP_CTL(pipe);
Jesse Barnese43823e2014-11-05 14:26:08 -0800239 u32 val = I915_READ(reg);
240
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300241 if ((val & VIDEO_DIP_ENABLE) == 0)
242 return false;
Jani Nikula052f62f2015-04-29 15:30:07 +0300243
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300244 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
245 return false;
246
247 return val & (VIDEO_DIP_ENABLE_AVI |
248 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
249 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Jesse Barnese43823e2014-11-05 14:26:08 -0800250}
251
Paulo Zanonifdf12502012-05-04 17:18:24 -0300252static void cpt_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100253 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100254 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200255 const void *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700256{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200257 const uint32_t *data = frame;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700258 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100259 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100260 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200261 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300262 u32 val = I915_READ(reg);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200263 int i;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700264
Paulo Zanoni822974a2012-05-28 16:42:51 -0300265 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
266
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530267 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100268 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700269
Paulo Zanoniecb97852012-05-04 17:18:21 -0300270 /* The DIP control register spec says that we need to update the AVI
271 * infoframe without clearing its enable bit */
Damien Lespiau178f7362013-08-06 20:32:18 +0100272 if (type != HDMI_INFOFRAME_TYPE_AVI)
273 val &= ~g4x_infoframe_enable(type);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300274
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300275 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700276
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300277 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700278 for (i = 0; i < len; i += 4) {
279 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
280 data++;
281 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300282 /* Write every possible data byte to force correct ECC calculation. */
283 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
284 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300285 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700286
Damien Lespiau178f7362013-08-06 20:32:18 +0100287 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300288 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200289 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700290
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300291 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300292 POSTING_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700293}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700294
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200295static bool cpt_infoframe_enabled(struct drm_encoder *encoder,
296 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800297{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200298 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
299 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
300 u32 val = I915_READ(TVIDEO_DIP_CTL(pipe));
Jesse Barnese43823e2014-11-05 14:26:08 -0800301
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300302 if ((val & VIDEO_DIP_ENABLE) == 0)
303 return false;
304
305 return val & (VIDEO_DIP_ENABLE_AVI |
306 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
307 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Jesse Barnese43823e2014-11-05 14:26:08 -0800308}
309
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700310static void vlv_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100311 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100312 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200313 const void *frame, ssize_t len)
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700314{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200315 const uint32_t *data = frame;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700316 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100317 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100318 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200319 i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300320 u32 val = I915_READ(reg);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200321 int i;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700322
Paulo Zanoni822974a2012-05-28 16:42:51 -0300323 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
324
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700325 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100326 val |= g4x_infoframe_index(type);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700327
Damien Lespiau178f7362013-08-06 20:32:18 +0100328 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300329
330 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700331
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300332 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700333 for (i = 0; i < len; i += 4) {
334 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
335 data++;
336 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300337 /* Write every possible data byte to force correct ECC calculation. */
338 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
339 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300340 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700341
Damien Lespiau178f7362013-08-06 20:32:18 +0100342 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300343 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200344 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700345
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300346 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300347 POSTING_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700348}
349
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200350static bool vlv_infoframe_enabled(struct drm_encoder *encoder,
351 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800352{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200353 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Jesse Barnes535afa22015-04-15 16:52:29 -0700354 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200355 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
356 u32 val = I915_READ(VLV_TVIDEO_DIP_CTL(pipe));
Jesse Barnese43823e2014-11-05 14:26:08 -0800357
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300358 if ((val & VIDEO_DIP_ENABLE) == 0)
359 return false;
Jesse Barnes535afa22015-04-15 16:52:29 -0700360
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300361 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
362 return false;
363
364 return val & (VIDEO_DIP_ENABLE_AVI |
365 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
366 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Jesse Barnese43823e2014-11-05 14:26:08 -0800367}
368
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300369static void hsw_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100370 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100371 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200372 const void *frame, ssize_t len)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300373{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200374 const uint32_t *data = frame;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300375 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100376 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100377 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200378 i915_reg_t ctl_reg = HSW_TVIDEO_DIP_CTL(cpu_transcoder);
379 i915_reg_t data_reg;
Damien Lespiau178f7362013-08-06 20:32:18 +0100380 int i;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300381 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300382
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300383 data_reg = hsw_dip_data_reg(dev_priv, cpu_transcoder, type, 0);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300384
Damien Lespiau178f7362013-08-06 20:32:18 +0100385 val &= ~hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300386 I915_WRITE(ctl_reg, val);
387
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300388 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300389 for (i = 0; i < len; i += 4) {
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300390 I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
391 type, i >> 2), *data);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300392 data++;
393 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300394 /* Write every possible data byte to force correct ECC calculation. */
395 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300396 I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
397 type, i >> 2), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300398 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300399
Damien Lespiau178f7362013-08-06 20:32:18 +0100400 val |= hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300401 I915_WRITE(ctl_reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300402 POSTING_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300403}
404
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200405static bool hsw_infoframe_enabled(struct drm_encoder *encoder,
406 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800407{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200408 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
409 u32 val = I915_READ(HSW_TVIDEO_DIP_CTL(pipe_config->cpu_transcoder));
Jesse Barnese43823e2014-11-05 14:26:08 -0800410
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300411 return val & (VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
412 VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
413 VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
Jesse Barnese43823e2014-11-05 14:26:08 -0800414}
415
Damien Lespiau5adaea72013-08-06 20:32:19 +0100416/*
417 * The data we write to the DIP data buffer registers is 1 byte bigger than the
418 * HDMI infoframe size because of an ECC/reserved byte at position 3 (starting
419 * at 0). It's also a byte used by DisplayPort so the same DIP registers can be
420 * used for both technologies.
421 *
422 * DW0: Reserved/ECC/DP | HB2 | HB1 | HB0
423 * DW1: DB3 | DB2 | DB1 | DB0
424 * DW2: DB7 | DB6 | DB5 | DB4
425 * DW3: ...
426 *
427 * (HB is Header Byte, DB is Data Byte)
428 *
429 * The hdmi pack() functions don't know about that hardware specific hole so we
430 * trick them by giving an offset into the buffer and moving back the header
431 * bytes by one.
432 */
Damien Lespiau9198ee52013-08-06 20:32:24 +0100433static void intel_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100434 const struct intel_crtc_state *crtc_state,
Damien Lespiau9198ee52013-08-06 20:32:24 +0100435 union hdmi_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700436{
437 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Damien Lespiau5adaea72013-08-06 20:32:19 +0100438 uint8_t buffer[VIDEO_DIP_DATA_SIZE];
439 ssize_t len;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700440
Damien Lespiau5adaea72013-08-06 20:32:19 +0100441 /* see comment above for the reason for this offset */
442 len = hdmi_infoframe_pack(frame, buffer + 1, sizeof(buffer) - 1);
443 if (len < 0)
444 return;
445
446 /* Insert the 'hole' (see big comment above) at position 3 */
447 buffer[0] = buffer[1];
448 buffer[1] = buffer[2];
449 buffer[2] = buffer[3];
450 buffer[3] = 0;
451 len++;
452
Maarten Lankhorstac240282016-11-23 15:57:00 +0100453 intel_hdmi->write_infoframe(encoder, crtc_state, frame->any.type, buffer, len);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700454}
455
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300456static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100457 const struct intel_crtc_state *crtc_state)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700458{
Ville Syrjäläabedc072013-01-17 16:31:31 +0200459 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Ville Syrjälä779c4c22017-01-11 14:57:24 +0200460 const struct drm_display_mode *adjusted_mode =
461 &crtc_state->base.adjusted_mode;
Damien Lespiau5adaea72013-08-06 20:32:19 +0100462 union hdmi_infoframe frame;
463 int ret;
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700464
Damien Lespiau5adaea72013-08-06 20:32:19 +0100465 ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
466 adjusted_mode);
467 if (ret < 0) {
468 DRM_ERROR("couldn't fill AVI infoframe\n");
469 return;
470 }
Paulo Zanonic846b612012-04-13 16:31:41 -0300471
Ville Syrjälä779c4c22017-01-11 14:57:24 +0200472 drm_hdmi_avi_infoframe_quant_range(&frame.avi, adjusted_mode,
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +0200473 crtc_state->limited_color_range ?
474 HDMI_QUANTIZATION_RANGE_LIMITED :
475 HDMI_QUANTIZATION_RANGE_FULL,
476 intel_hdmi->rgb_quant_range_selectable);
Ville Syrjäläabedc072013-01-17 16:31:31 +0200477
Maarten Lankhorstac240282016-11-23 15:57:00 +0100478 intel_write_infoframe(encoder, crtc_state, &frame);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700479}
480
Maarten Lankhorstac240282016-11-23 15:57:00 +0100481static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder,
482 const struct intel_crtc_state *crtc_state)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700483{
Damien Lespiau5adaea72013-08-06 20:32:19 +0100484 union hdmi_infoframe frame;
485 int ret;
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700486
Damien Lespiau5adaea72013-08-06 20:32:19 +0100487 ret = hdmi_spd_infoframe_init(&frame.spd, "Intel", "Integrated gfx");
488 if (ret < 0) {
489 DRM_ERROR("couldn't fill SPD infoframe\n");
490 return;
491 }
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700492
Damien Lespiau5adaea72013-08-06 20:32:19 +0100493 frame.spd.sdi = HDMI_SPD_SDI_PC;
494
Maarten Lankhorstac240282016-11-23 15:57:00 +0100495 intel_write_infoframe(encoder, crtc_state, &frame);
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700496}
497
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100498static void
499intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100500 const struct intel_crtc_state *crtc_state)
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100501{
502 union hdmi_infoframe frame;
503 int ret;
504
505 ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100506 &crtc_state->base.adjusted_mode);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100507 if (ret < 0)
508 return;
509
Maarten Lankhorstac240282016-11-23 15:57:00 +0100510 intel_write_infoframe(encoder, crtc_state, &frame);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100511}
512
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300513static void g4x_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200514 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100515 const struct intel_crtc_state *crtc_state,
516 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300517{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100518 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200519 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
520 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200521 i915_reg_t reg = VIDEO_DIP_CTL;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300522 u32 val = I915_READ(reg);
Ville Syrjälä822cdc52014-01-23 23:15:34 +0200523 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300524
Daniel Vetterafba0182012-06-12 16:36:45 +0200525 assert_hdmi_port_disabled(intel_hdmi);
526
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300527 /* If the registers were not initialized yet, they might be zeroes,
528 * which means we're selecting the AVI DIP and we're setting its
529 * frequency to once. This seems to really confuse the HW and make
530 * things stop working (the register spec says the AVI always needs to
531 * be sent every VSync). So here we avoid writing to the register more
532 * than we need and also explicitly select the AVI DIP and explicitly
533 * set its frequency to every VSync. Avoiding to write it twice seems to
534 * be enough to solve the problem, but being defensive shouldn't hurt us
535 * either. */
536 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
537
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200538 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300539 if (!(val & VIDEO_DIP_ENABLE))
540 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300541 if (port != (val & VIDEO_DIP_PORT_MASK)) {
542 DRM_DEBUG_KMS("video DIP still enabled on port %c\n",
543 (val & VIDEO_DIP_PORT_MASK) >> 29);
544 return;
545 }
546 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
547 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300548 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300549 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300550 return;
551 }
552
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300553 if (port != (val & VIDEO_DIP_PORT_MASK)) {
554 if (val & VIDEO_DIP_ENABLE) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300555 DRM_DEBUG_KMS("video DIP already enabled on port %c\n",
556 (val & VIDEO_DIP_PORT_MASK) >> 29);
557 return;
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300558 }
559 val &= ~VIDEO_DIP_PORT_MASK;
560 val |= port;
561 }
562
Paulo Zanoni822974a2012-05-28 16:42:51 -0300563 val |= VIDEO_DIP_ENABLE;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300564 val &= ~(VIDEO_DIP_ENABLE_AVI |
565 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300566
Paulo Zanonif278d972012-05-28 16:42:50 -0300567 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300568 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300569
Maarten Lankhorstac240282016-11-23 15:57:00 +0100570 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
571 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
572 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300573}
574
Maarten Lankhorstac240282016-11-23 15:57:00 +0100575static bool hdmi_sink_is_deep_color(const struct drm_connector_state *conn_state)
Ville Syrjälä6d674152015-05-05 17:06:20 +0300576{
Maarten Lankhorstac240282016-11-23 15:57:00 +0100577 struct drm_connector *connector = conn_state->connector;
Ville Syrjälä6d674152015-05-05 17:06:20 +0300578
579 /*
580 * HDMI cloning is only supported on g4x which doesn't
581 * support deep color or GCP infoframes anyway so no
582 * need to worry about multiple HDMI sinks here.
583 */
Ville Syrjälä6d674152015-05-05 17:06:20 +0300584
Maarten Lankhorstac240282016-11-23 15:57:00 +0100585 return connector->display_info.bpc > 8;
Ville Syrjälä6d674152015-05-05 17:06:20 +0300586}
587
Ville Syrjälä12aa3292015-05-05 17:06:21 +0300588/*
589 * Determine if default_phase=1 can be indicated in the GCP infoframe.
590 *
591 * From HDMI specification 1.4a:
592 * - The first pixel of each Video Data Period shall always have a pixel packing phase of 0
593 * - The first pixel following each Video Data Period shall have a pixel packing phase of 0
594 * - The PP bits shall be constant for all GCPs and will be equal to the last packing phase
595 * - The first pixel following every transition of HSYNC or VSYNC shall have a pixel packing
596 * phase of 0
597 */
598static bool gcp_default_phase_possible(int pipe_bpp,
599 const struct drm_display_mode *mode)
600{
601 unsigned int pixels_per_group;
602
603 switch (pipe_bpp) {
604 case 30:
605 /* 4 pixels in 5 clocks */
606 pixels_per_group = 4;
607 break;
608 case 36:
609 /* 2 pixels in 3 clocks */
610 pixels_per_group = 2;
611 break;
612 case 48:
613 /* 1 pixel in 2 clocks */
614 pixels_per_group = 1;
615 break;
616 default:
617 /* phase information not relevant for 8bpc */
618 return false;
619 }
620
621 return mode->crtc_hdisplay % pixels_per_group == 0 &&
622 mode->crtc_htotal % pixels_per_group == 0 &&
623 mode->crtc_hblank_start % pixels_per_group == 0 &&
624 mode->crtc_hblank_end % pixels_per_group == 0 &&
625 mode->crtc_hsync_start % pixels_per_group == 0 &&
626 mode->crtc_hsync_end % pixels_per_group == 0 &&
627 ((mode->flags & DRM_MODE_FLAG_INTERLACE) == 0 ||
628 mode->crtc_htotal/2 % pixels_per_group == 0);
629}
630
Maarten Lankhorstac240282016-11-23 15:57:00 +0100631static bool intel_hdmi_set_gcp_infoframe(struct drm_encoder *encoder,
632 const struct intel_crtc_state *crtc_state,
633 const struct drm_connector_state *conn_state)
Ville Syrjälä6d674152015-05-05 17:06:20 +0300634{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100635 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100636 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200637 i915_reg_t reg;
638 u32 val = 0;
Ville Syrjälä6d674152015-05-05 17:06:20 +0300639
640 if (HAS_DDI(dev_priv))
Maarten Lankhorstac240282016-11-23 15:57:00 +0100641 reg = HSW_TVIDEO_DIP_GCP(crtc_state->cpu_transcoder);
Wayne Boyer666a4532015-12-09 12:29:35 -0800642 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300643 reg = VLV_TVIDEO_DIP_GCP(crtc->pipe);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +0300644 else if (HAS_PCH_SPLIT(dev_priv))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300645 reg = TVIDEO_DIP_GCP(crtc->pipe);
646 else
647 return false;
648
649 /* Indicate color depth whenever the sink supports deep color */
Maarten Lankhorstac240282016-11-23 15:57:00 +0100650 if (hdmi_sink_is_deep_color(conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300651 val |= GCP_COLOR_INDICATION;
652
Ville Syrjälä12aa3292015-05-05 17:06:21 +0300653 /* Enable default_phase whenever the display mode is suitably aligned */
Maarten Lankhorstac240282016-11-23 15:57:00 +0100654 if (gcp_default_phase_possible(crtc_state->pipe_bpp,
655 &crtc_state->base.adjusted_mode))
Ville Syrjälä12aa3292015-05-05 17:06:21 +0300656 val |= GCP_DEFAULT_PHASE_ENABLE;
657
Ville Syrjälä6d674152015-05-05 17:06:20 +0300658 I915_WRITE(reg, val);
659
660 return val != 0;
661}
662
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300663static void ibx_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200664 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100665 const struct intel_crtc_state *crtc_state,
666 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300667{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100668 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100669 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200670 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
671 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200672 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300673 u32 val = I915_READ(reg);
Ville Syrjälä822cdc52014-01-23 23:15:34 +0200674 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300675
Daniel Vetterafba0182012-06-12 16:36:45 +0200676 assert_hdmi_port_disabled(intel_hdmi);
677
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300678 /* See the big comment in g4x_set_infoframes() */
679 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
680
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200681 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300682 if (!(val & VIDEO_DIP_ENABLE))
683 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300684 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
685 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
686 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300687 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300688 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300689 return;
690 }
691
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300692 if (port != (val & VIDEO_DIP_PORT_MASK)) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300693 WARN(val & VIDEO_DIP_ENABLE,
694 "DIP already enabled on port %c\n",
695 (val & VIDEO_DIP_PORT_MASK) >> 29);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300696 val &= ~VIDEO_DIP_PORT_MASK;
697 val |= port;
698 }
699
Paulo Zanoni822974a2012-05-28 16:42:51 -0300700 val |= VIDEO_DIP_ENABLE;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300701 val &= ~(VIDEO_DIP_ENABLE_AVI |
702 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
703 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300704
Maarten Lankhorstac240282016-11-23 15:57:00 +0100705 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300706 val |= VIDEO_DIP_ENABLE_GCP;
707
Paulo Zanonif278d972012-05-28 16:42:50 -0300708 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300709 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300710
Maarten Lankhorstac240282016-11-23 15:57:00 +0100711 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
712 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
713 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300714}
715
716static void cpt_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200717 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100718 const struct intel_crtc_state *crtc_state,
719 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300720{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100721 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100722 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300723 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200724 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300725 u32 val = I915_READ(reg);
726
Daniel Vetterafba0182012-06-12 16:36:45 +0200727 assert_hdmi_port_disabled(intel_hdmi);
728
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300729 /* See the big comment in g4x_set_infoframes() */
730 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
731
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200732 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300733 if (!(val & VIDEO_DIP_ENABLE))
734 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300735 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
736 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
737 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300738 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300739 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300740 return;
741 }
742
Paulo Zanoni822974a2012-05-28 16:42:51 -0300743 /* Set both together, unset both together: see the spec. */
744 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300745 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300746 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300747
Maarten Lankhorstac240282016-11-23 15:57:00 +0100748 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300749 val |= VIDEO_DIP_ENABLE_GCP;
750
Paulo Zanoni822974a2012-05-28 16:42:51 -0300751 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300752 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300753
Maarten Lankhorstac240282016-11-23 15:57:00 +0100754 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
755 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
756 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300757}
758
759static void vlv_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200760 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100761 const struct intel_crtc_state *crtc_state,
762 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300763{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100764 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700765 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100766 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300767 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200768 i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300769 u32 val = I915_READ(reg);
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700770 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300771
Daniel Vetterafba0182012-06-12 16:36:45 +0200772 assert_hdmi_port_disabled(intel_hdmi);
773
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300774 /* See the big comment in g4x_set_infoframes() */
775 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
776
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200777 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300778 if (!(val & VIDEO_DIP_ENABLE))
779 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300780 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
781 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
782 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300783 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300784 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300785 return;
786 }
787
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700788 if (port != (val & VIDEO_DIP_PORT_MASK)) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300789 WARN(val & VIDEO_DIP_ENABLE,
790 "DIP already enabled on port %c\n",
791 (val & VIDEO_DIP_PORT_MASK) >> 29);
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700792 val &= ~VIDEO_DIP_PORT_MASK;
793 val |= port;
794 }
795
Paulo Zanoni822974a2012-05-28 16:42:51 -0300796 val |= VIDEO_DIP_ENABLE;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300797 val &= ~(VIDEO_DIP_ENABLE_AVI |
798 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
799 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300800
Maarten Lankhorstac240282016-11-23 15:57:00 +0100801 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300802 val |= VIDEO_DIP_ENABLE_GCP;
803
Paulo Zanoni822974a2012-05-28 16:42:51 -0300804 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300805 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300806
Maarten Lankhorstac240282016-11-23 15:57:00 +0100807 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
808 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
809 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300810}
811
812static void hsw_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200813 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100814 const struct intel_crtc_state *crtc_state,
815 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300816{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100817 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300818 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100819 i915_reg_t reg = HSW_TVIDEO_DIP_CTL(crtc_state->cpu_transcoder);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300820 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300821
Daniel Vetterafba0182012-06-12 16:36:45 +0200822 assert_hdmi_port_disabled(intel_hdmi);
823
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300824 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
825 VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
826 VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
827
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200828 if (!enable) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300829 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300830 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300831 return;
832 }
833
Maarten Lankhorstac240282016-11-23 15:57:00 +0100834 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300835 val |= VIDEO_DIP_ENABLE_GCP_HSW;
836
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300837 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300838 POSTING_READ(reg);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300839
Maarten Lankhorstac240282016-11-23 15:57:00 +0100840 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
841 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
842 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300843}
844
Ville Syrjäläb2ccb822016-05-02 22:08:24 +0300845void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
846{
847 struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
848 struct i2c_adapter *adapter =
849 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
850
851 if (hdmi->dp_dual_mode.type < DRM_DP_DUAL_MODE_TYPE2_DVI)
852 return;
853
854 DRM_DEBUG_KMS("%s DP dual mode adaptor TMDS output\n",
855 enable ? "Enabling" : "Disabling");
856
857 drm_dp_dual_mode_set_tmds_output(hdmi->dp_dual_mode.type,
858 adapter, enable);
859}
860
Maarten Lankhorstac240282016-11-23 15:57:00 +0100861static void intel_hdmi_prepare(struct intel_encoder *encoder,
862 const struct intel_crtc_state *crtc_state)
Eric Anholt7d573822009-01-02 13:33:00 -0800863{
Daniel Vetterc59423a2013-07-21 21:37:04 +0200864 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100865 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100866 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Daniel Vetterc59423a2013-07-21 21:37:04 +0200867 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100868 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300869 u32 hdmi_val;
Eric Anholt7d573822009-01-02 13:33:00 -0800870
Ville Syrjäläb2ccb822016-05-02 22:08:24 +0300871 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
872
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300873 hdmi_val = SDVO_ENCODING_HDMI;
Maarten Lankhorstac240282016-11-23 15:57:00 +0100874 if (!HAS_PCH_SPLIT(dev_priv) && crtc_state->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +0300875 hdmi_val |= HDMI_COLOR_RANGE_16_235;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400876 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300877 hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400878 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300879 hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800880
Maarten Lankhorstac240282016-11-23 15:57:00 +0100881 if (crtc_state->pipe_bpp > 24)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300882 hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700883 else
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300884 hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700885
Maarten Lankhorstac240282016-11-23 15:57:00 +0100886 if (crtc_state->has_hdmi_sink)
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300887 hdmi_val |= HDMI_MODE_SELECT_HDMI;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800888
Tvrtko Ursulin6e266952016-10-13 11:02:53 +0100889 if (HAS_PCH_CPT(dev_priv))
Daniel Vetterc59423a2013-07-21 21:37:04 +0200890 hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100891 else if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +0300892 hdmi_val |= SDVO_PIPE_SEL_CHV(crtc->pipe);
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300893 else
Daniel Vetterc59423a2013-07-21 21:37:04 +0200894 hdmi_val |= SDVO_PIPE_SEL(crtc->pipe);
Eric Anholt7d573822009-01-02 13:33:00 -0800895
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300896 I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
897 POSTING_READ(intel_hdmi->hdmi_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800898}
899
Daniel Vetter85234cd2012-07-02 13:27:29 +0200900static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
901 enum pipe *pipe)
Eric Anholt7d573822009-01-02 13:33:00 -0800902{
Daniel Vetter85234cd2012-07-02 13:27:29 +0200903 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100904 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200905 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
906 u32 tmp;
Imre Deak5b092172016-02-12 18:55:20 +0200907 bool ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200908
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +0200909 if (!intel_display_power_get_if_enabled(dev_priv,
910 encoder->power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200911 return false;
912
Imre Deak5b092172016-02-12 18:55:20 +0200913 ret = false;
914
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300915 tmp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200916
917 if (!(tmp & SDVO_ENABLE))
Imre Deak5b092172016-02-12 18:55:20 +0200918 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200919
Tvrtko Ursulin6e266952016-10-13 11:02:53 +0100920 if (HAS_PCH_CPT(dev_priv))
Daniel Vetter85234cd2012-07-02 13:27:29 +0200921 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100922 else if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä71485e02014-04-09 13:28:55 +0300923 *pipe = SDVO_PORT_TO_PIPE_CHV(tmp);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200924 else
925 *pipe = PORT_TO_PIPE(tmp);
926
Imre Deak5b092172016-02-12 18:55:20 +0200927 ret = true;
928
929out:
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +0200930 intel_display_power_put(dev_priv, encoder->power_domain);
Imre Deak5b092172016-02-12 18:55:20 +0200931
932 return ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200933}
934
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700935static void intel_hdmi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200936 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700937{
938 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Ville Syrjälä8c875fc2014-09-12 15:46:29 +0300939 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100940 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700941 u32 tmp, flags = 0;
Ville Syrjälä18442d02013-09-13 16:00:08 +0300942 int dotclock;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700943
944 tmp = I915_READ(intel_hdmi->hdmi_reg);
945
946 if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
947 flags |= DRM_MODE_FLAG_PHSYNC;
948 else
949 flags |= DRM_MODE_FLAG_NHSYNC;
950
951 if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
952 flags |= DRM_MODE_FLAG_PVSYNC;
953 else
954 flags |= DRM_MODE_FLAG_NVSYNC;
955
Daniel Vetter6897b4b2014-04-24 23:54:47 +0200956 if (tmp & HDMI_MODE_SELECT_HDMI)
957 pipe_config->has_hdmi_sink = true;
958
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200959 if (intel_hdmi->infoframe_enabled(&encoder->base, pipe_config))
Jesse Barnese43823e2014-11-05 14:26:08 -0800960 pipe_config->has_infoframe = true;
961
Jani Nikulac84db772014-09-17 15:34:58 +0300962 if (tmp & SDVO_AUDIO_ENABLE)
Daniel Vetter9ed109a2014-04-24 23:54:52 +0200963 pipe_config->has_audio = true;
964
Tvrtko Ursulin6e266952016-10-13 11:02:53 +0100965 if (!HAS_PCH_SPLIT(dev_priv) &&
Ville Syrjälä8c875fc2014-09-12 15:46:29 +0300966 tmp & HDMI_COLOR_RANGE_16_235)
967 pipe_config->limited_color_range = true;
968
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200969 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä18442d02013-09-13 16:00:08 +0300970
971 if ((tmp & SDVO_COLOR_FORMAT_MASK) == HDMI_COLOR_FORMAT_12bpc)
972 dotclock = pipe_config->port_clock * 2 / 3;
973 else
974 dotclock = pipe_config->port_clock;
975
Ville Syrjäläbe69a132015-05-05 17:06:26 +0300976 if (pipe_config->pixel_multiplier)
977 dotclock /= pipe_config->pixel_multiplier;
978
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200979 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +0300980
981 pipe_config->lane_count = 4;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700982}
983
Maarten Lankhorstdf18e722016-11-08 13:55:37 +0100984static void intel_enable_hdmi_audio(struct intel_encoder *encoder,
985 struct intel_crtc_state *pipe_config,
986 struct drm_connector_state *conn_state)
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300987{
Maarten Lankhorstac240282016-11-23 15:57:00 +0100988 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300989
Maarten Lankhorstac240282016-11-23 15:57:00 +0100990 WARN_ON(!pipe_config->has_hdmi_sink);
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300991 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
992 pipe_name(crtc->pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +0100993 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300994}
995
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200996static void g4x_enable_hdmi(struct intel_encoder *encoder,
997 struct intel_crtc_state *pipe_config,
998 struct drm_connector_state *conn_state)
Eric Anholt7d573822009-01-02 13:33:00 -0800999{
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001000 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001001 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001002 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Eric Anholt7d573822009-01-02 13:33:00 -08001003 u32 temp;
1004
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001005 temp = I915_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +00001006
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001007 temp |= SDVO_ENABLE;
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001008 if (pipe_config->has_audio)
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001009 temp |= SDVO_AUDIO_ENABLE;
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001010
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001011 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1012 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001013
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001014 if (pipe_config->has_audio)
1015 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001016}
1017
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001018static void ibx_enable_hdmi(struct intel_encoder *encoder,
1019 struct intel_crtc_state *pipe_config,
1020 struct drm_connector_state *conn_state)
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001021{
1022 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001023 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001024 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1025 u32 temp;
1026
1027 temp = I915_READ(intel_hdmi->hdmi_reg);
1028
1029 temp |= SDVO_ENABLE;
Maarten Lankhorstac240282016-11-23 15:57:00 +01001030 if (pipe_config->has_audio)
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001031 temp |= SDVO_AUDIO_ENABLE;
1032
1033 /*
1034 * HW workaround, need to write this twice for issue
1035 * that may result in first write getting masked.
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001036 */
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001037 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1038 POSTING_READ(intel_hdmi->hdmi_reg);
1039 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1040 POSTING_READ(intel_hdmi->hdmi_reg);
1041
1042 /*
1043 * HW workaround, need to toggle enable bit off and on
1044 * for 12bpc with pixel repeat.
1045 *
1046 * FIXME: BSpec says this should be done at the end of
1047 * of the modeset sequence, so not sure if this isn't too soon.
1048 */
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001049 if (pipe_config->pipe_bpp > 24 &&
1050 pipe_config->pixel_multiplier > 1) {
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001051 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
1052 POSTING_READ(intel_hdmi->hdmi_reg);
1053
1054 /*
1055 * HW workaround, need to write this twice for issue
1056 * that may result in first write getting masked.
1057 */
1058 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1059 POSTING_READ(intel_hdmi->hdmi_reg);
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001060 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1061 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001062 }
Jani Nikulac1dec792014-10-27 16:26:56 +02001063
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001064 if (pipe_config->has_audio)
1065 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001066}
1067
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001068static void cpt_enable_hdmi(struct intel_encoder *encoder,
1069 struct intel_crtc_state *pipe_config,
1070 struct drm_connector_state *conn_state)
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001071{
1072 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001073 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +01001074 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001075 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1076 enum pipe pipe = crtc->pipe;
1077 u32 temp;
1078
1079 temp = I915_READ(intel_hdmi->hdmi_reg);
1080
1081 temp |= SDVO_ENABLE;
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001082 if (pipe_config->has_audio)
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001083 temp |= SDVO_AUDIO_ENABLE;
1084
1085 /*
1086 * WaEnableHDMI8bpcBefore12bpc:snb,ivb
1087 *
1088 * The procedure for 12bpc is as follows:
1089 * 1. disable HDMI clock gating
1090 * 2. enable HDMI with 8bpc
1091 * 3. enable HDMI with 12bpc
1092 * 4. enable HDMI clock gating
1093 */
1094
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001095 if (pipe_config->pipe_bpp > 24) {
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001096 I915_WRITE(TRANS_CHICKEN1(pipe),
1097 I915_READ(TRANS_CHICKEN1(pipe)) |
1098 TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
1099
1100 temp &= ~SDVO_COLOR_FORMAT_MASK;
1101 temp |= SDVO_COLOR_FORMAT_8bpc;
Jani Nikulac1dec792014-10-27 16:26:56 +02001102 }
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001103
1104 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1105 POSTING_READ(intel_hdmi->hdmi_reg);
1106
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001107 if (pipe_config->pipe_bpp > 24) {
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001108 temp &= ~SDVO_COLOR_FORMAT_MASK;
1109 temp |= HDMI_COLOR_FORMAT_12bpc;
1110
1111 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1112 POSTING_READ(intel_hdmi->hdmi_reg);
1113
1114 I915_WRITE(TRANS_CHICKEN1(pipe),
1115 I915_READ(TRANS_CHICKEN1(pipe)) &
1116 ~TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
1117 }
1118
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001119 if (pipe_config->has_audio)
1120 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
Jani Nikulab76cf762013-07-30 12:20:31 +03001121}
Jesse Barnes89b667f2013-04-18 14:51:36 -07001122
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001123static void vlv_enable_hdmi(struct intel_encoder *encoder,
1124 struct intel_crtc_state *pipe_config,
1125 struct drm_connector_state *conn_state)
Jani Nikulab76cf762013-07-30 12:20:31 +03001126{
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001127}
1128
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001129static void intel_disable_hdmi(struct intel_encoder *encoder,
1130 struct intel_crtc_state *old_crtc_state,
1131 struct drm_connector_state *old_conn_state)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001132{
1133 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001134 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001135 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Maarten Lankhorstac240282016-11-23 15:57:00 +01001136 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001137 u32 temp;
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001138
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001139 temp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001140
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001141 temp &= ~(SDVO_ENABLE | SDVO_AUDIO_ENABLE);
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001142 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1143 POSTING_READ(intel_hdmi->hdmi_reg);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001144
1145 /*
1146 * HW workaround for IBX, we need to move the port
1147 * to transcoder A after disabling it to allow the
1148 * matching DP port to be enabled on transcoder A.
1149 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001150 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02001151 /*
1152 * We get CPU/PCH FIFO underruns on the other pipe when
1153 * doing the workaround. Sweep them under the rug.
1154 */
1155 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1156 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1157
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001158 temp &= ~SDVO_PIPE_B_SELECT;
1159 temp |= SDVO_ENABLE;
1160 /*
1161 * HW workaround, need to write this twice for issue
1162 * that may result in first write getting masked.
1163 */
1164 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1165 POSTING_READ(intel_hdmi->hdmi_reg);
1166 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1167 POSTING_READ(intel_hdmi->hdmi_reg);
1168
1169 temp &= ~SDVO_ENABLE;
1170 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1171 POSTING_READ(intel_hdmi->hdmi_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02001172
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02001173 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02001174 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1175 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001176 }
Ville Syrjälä6d674152015-05-05 17:06:20 +03001177
Maarten Lankhorstac240282016-11-23 15:57:00 +01001178 intel_hdmi->set_infoframes(&encoder->base, false, old_crtc_state, old_conn_state);
Ville Syrjäläb2ccb822016-05-02 22:08:24 +03001179
1180 intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
Eric Anholt7d573822009-01-02 13:33:00 -08001181}
1182
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001183static void g4x_disable_hdmi(struct intel_encoder *encoder,
1184 struct intel_crtc_state *old_crtc_state,
1185 struct drm_connector_state *old_conn_state)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001186{
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001187 if (old_crtc_state->has_audio)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001188 intel_audio_codec_disable(encoder);
1189
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001190 intel_disable_hdmi(encoder, old_crtc_state, old_conn_state);
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001191}
1192
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001193static void pch_disable_hdmi(struct intel_encoder *encoder,
1194 struct intel_crtc_state *old_crtc_state,
1195 struct drm_connector_state *old_conn_state)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001196{
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001197 if (old_crtc_state->has_audio)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001198 intel_audio_codec_disable(encoder);
1199}
1200
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001201static void pch_post_disable_hdmi(struct intel_encoder *encoder,
1202 struct intel_crtc_state *old_crtc_state,
1203 struct drm_connector_state *old_conn_state)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001204{
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001205 intel_disable_hdmi(encoder, old_crtc_state, old_conn_state);
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001206}
1207
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001208static int intel_hdmi_source_max_tmds_clock(struct drm_i915_private *dev_priv)
Daniel Vetter7d148ef52013-07-22 18:02:39 +02001209{
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001210 if (IS_G4X(dev_priv))
Daniel Vetter7d148ef52013-07-22 18:02:39 +02001211 return 165000;
Shashank Sharma14292b72017-03-13 16:54:04 +05301212 else if (IS_GEMINILAKE(dev_priv))
1213 return 594000;
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001214 else if (IS_HASWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 8)
Daniel Vetter7d148ef52013-07-22 18:02:39 +02001215 return 300000;
1216 else
1217 return 225000;
1218}
1219
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001220static int hdmi_port_clock_limit(struct intel_hdmi *hdmi,
1221 bool respect_downstream_limits)
1222{
1223 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
1224 int max_tmds_clock = intel_hdmi_source_max_tmds_clock(to_i915(dev));
1225
1226 if (respect_downstream_limits) {
Ville Syrjälä8cadab02016-09-28 16:51:43 +03001227 struct intel_connector *connector = hdmi->attached_connector;
1228 const struct drm_display_info *info = &connector->base.display_info;
1229
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001230 if (hdmi->dp_dual_mode.max_tmds_clock)
1231 max_tmds_clock = min(max_tmds_clock,
1232 hdmi->dp_dual_mode.max_tmds_clock);
Ville Syrjälä8cadab02016-09-28 16:51:43 +03001233
1234 if (info->max_tmds_clock)
1235 max_tmds_clock = min(max_tmds_clock,
1236 info->max_tmds_clock);
1237 else if (!hdmi->has_hdmi_sink)
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001238 max_tmds_clock = min(max_tmds_clock, 165000);
1239 }
1240
1241 return max_tmds_clock;
1242}
1243
Damien Lespiauc19de8e2013-11-28 15:29:18 +00001244static enum drm_mode_status
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001245hdmi_port_clock_valid(struct intel_hdmi *hdmi,
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001246 int clock, bool respect_downstream_limits)
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001247{
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01001248 struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001249
1250 if (clock < 25000)
1251 return MODE_CLOCK_LOW;
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001252 if (clock > hdmi_port_clock_limit(hdmi, respect_downstream_limits))
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001253 return MODE_CLOCK_HIGH;
1254
Ville Syrjälä5e6ccc02015-07-06 14:44:11 +03001255 /* BXT DPLL can't generate 223-240 MHz */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001256 if (IS_GEN9_LP(dev_priv) && clock > 223333 && clock < 240000)
Ville Syrjälä5e6ccc02015-07-06 14:44:11 +03001257 return MODE_CLOCK_RANGE;
1258
1259 /* CHV DPLL can't generate 216-240 MHz */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01001260 if (IS_CHERRYVIEW(dev_priv) && clock > 216000 && clock < 240000)
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001261 return MODE_CLOCK_RANGE;
1262
1263 return MODE_OK;
1264}
1265
1266static enum drm_mode_status
Damien Lespiauc19de8e2013-11-28 15:29:18 +00001267intel_hdmi_mode_valid(struct drm_connector *connector,
1268 struct drm_display_mode *mode)
Eric Anholt7d573822009-01-02 13:33:00 -08001269{
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001270 struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
1271 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001272 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001273 enum drm_mode_status status;
1274 int clock;
Mika Kahola587bf492016-02-02 15:16:39 +02001275 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
Eric Anholt7d573822009-01-02 13:33:00 -08001276
1277 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1278 return MODE_NO_DBLESCAN;
1279
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001280 clock = mode->clock;
Mika Kahola587bf492016-02-02 15:16:39 +02001281
1282 if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
1283 clock *= 2;
1284
1285 if (clock > max_dotclk)
1286 return MODE_CLOCK_HIGH;
1287
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001288 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
1289 clock *= 2;
1290
1291 /* check if we can do 8bpc */
1292 status = hdmi_port_clock_valid(hdmi, clock, true);
1293
1294 /* if we can't do 8bpc we may still be able to do 12bpc */
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001295 if (!HAS_GMCH_DISPLAY(dev_priv) && status != MODE_OK)
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001296 status = hdmi_port_clock_valid(hdmi, clock * 3 / 2, true);
1297
1298 return status;
Eric Anholt7d573822009-01-02 13:33:00 -08001299}
1300
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +02001301static bool hdmi_12bpc_possible(struct intel_crtc_state *crtc_state)
Ville Syrjälä71800632014-03-03 16:15:29 +02001302{
Ville Syrjäläc750bdd2017-02-13 19:58:18 +02001303 struct drm_i915_private *dev_priv =
1304 to_i915(crtc_state->base.crtc->dev);
1305 struct drm_atomic_state *state = crtc_state->base.state;
1306 struct drm_connector_state *connector_state;
1307 struct drm_connector *connector;
1308 int i;
Ville Syrjälä71800632014-03-03 16:15:29 +02001309
Ville Syrjäläc750bdd2017-02-13 19:58:18 +02001310 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä71800632014-03-03 16:15:29 +02001311 return false;
1312
Ville Syrjälä71800632014-03-03 16:15:29 +02001313 /*
1314 * HDMI 12bpc affects the clocks, so it's only possible
1315 * when not cloning with other encoder types.
1316 */
Ville Syrjäläc750bdd2017-02-13 19:58:18 +02001317 if (crtc_state->output_types != 1 << INTEL_OUTPUT_HDMI)
1318 return false;
1319
1320 for_each_connector_in_state(state, connector, connector_state, i) {
1321 const struct drm_display_info *info = &connector->display_info;
1322
1323 if (connector_state->crtc != crtc_state->base.crtc)
1324 continue;
1325
1326 if ((info->edid_hdmi_dc_modes & DRM_EDID_HDMI_DC_36) == 0)
1327 return false;
1328 }
1329
Ander Conselvan de Oliveira46649d82017-04-24 13:47:18 +03001330 /* Display Wa #1139 */
1331 if (IS_GLK_REVID(dev_priv, 0, GLK_REVID_A1) &&
1332 crtc_state->base.adjusted_mode.htotal > 5460)
1333 return false;
1334
Ville Syrjäläc750bdd2017-02-13 19:58:18 +02001335 return true;
Ville Syrjälä71800632014-03-03 16:15:29 +02001336}
1337
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001338bool intel_hdmi_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001339 struct intel_crtc_state *pipe_config,
1340 struct drm_connector_state *conn_state)
Eric Anholt7d573822009-01-02 13:33:00 -08001341{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001342 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001343 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001344 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Shashank Sharma15953632017-03-13 16:54:03 +05301345 struct drm_scdc *scdc = &conn_state->connector->display_info.hdmi.scdc;
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001346 int clock_8bpc = pipe_config->base.adjusted_mode.crtc_clock;
1347 int clock_12bpc = clock_8bpc * 3 / 2;
Daniel Vettere29c22c2013-02-21 00:00:16 +01001348 int desired_bpp;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001349
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001350 pipe_config->has_hdmi_sink = intel_hdmi->has_hdmi_sink;
1351
Jesse Barnese43823e2014-11-05 14:26:08 -08001352 if (pipe_config->has_hdmi_sink)
1353 pipe_config->has_infoframe = true;
1354
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001355 if (intel_hdmi->color_range_auto) {
1356 /* See CEA-861-E - 5.1 Default Encoding Parameters */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001357 pipe_config->limited_color_range =
1358 pipe_config->has_hdmi_sink &&
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001359 drm_default_rgb_quant_range(adjusted_mode) ==
1360 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001361 } else {
1362 pipe_config->limited_color_range =
1363 intel_hdmi->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001364 }
1365
Clint Taylor697c4072014-09-02 17:03:36 -07001366 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) {
1367 pipe_config->pixel_multiplier = 2;
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001368 clock_8bpc *= 2;
Ville Syrjälä3320e372015-05-05 17:06:27 +03001369 clock_12bpc *= 2;
Clint Taylor697c4072014-09-02 17:03:36 -07001370 }
1371
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001372 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv))
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001373 pipe_config->has_pch_encoder = true;
1374
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001375 if (pipe_config->has_hdmi_sink && intel_hdmi->has_audio)
1376 pipe_config->has_audio = true;
1377
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001378 /*
1379 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
1380 * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
Daniel Vetter325b9d02013-04-19 11:24:33 +02001381 * outputs. We also need to check that the higher clock still fits
1382 * within limits.
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001383 */
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001384 if (pipe_config->pipe_bpp > 8*3 && pipe_config->has_hdmi_sink &&
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001385 hdmi_port_clock_valid(intel_hdmi, clock_12bpc, true) == MODE_OK &&
Ville Syrjälä7a0baa62015-06-30 15:33:54 +03001386 hdmi_12bpc_possible(pipe_config)) {
Daniel Vettere29c22c2013-02-21 00:00:16 +01001387 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
1388 desired_bpp = 12*3;
Daniel Vetter325b9d02013-04-19 11:24:33 +02001389
1390 /* Need to adjust the port link by 1.5x for 12bpc. */
Daniel Vetterff9a6752013-06-01 17:16:21 +02001391 pipe_config->port_clock = clock_12bpc;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001392 } else {
Daniel Vettere29c22c2013-02-21 00:00:16 +01001393 DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
1394 desired_bpp = 8*3;
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001395
1396 pipe_config->port_clock = clock_8bpc;
Daniel Vettere29c22c2013-02-21 00:00:16 +01001397 }
1398
1399 if (!pipe_config->bw_constrained) {
Dhinakaran Pandiyanb64b7a62017-04-04 11:16:05 -07001400 DRM_DEBUG_KMS("forcing pipe bpp to %i for HDMI\n", desired_bpp);
Daniel Vettere29c22c2013-02-21 00:00:16 +01001401 pipe_config->pipe_bpp = desired_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001402 }
1403
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001404 if (hdmi_port_clock_valid(intel_hdmi, pipe_config->port_clock,
1405 false) != MODE_OK) {
1406 DRM_DEBUG_KMS("unsupported HDMI clock, rejecting mode\n");
Daniel Vetter325b9d02013-04-19 11:24:33 +02001407 return false;
1408 }
1409
Ville Syrjälä28b468a2015-09-08 13:40:48 +03001410 /* Set user selected PAR to incoming mode's member */
Maarten Lankhorst0e9f25d2017-05-01 15:37:53 +02001411 adjusted_mode->picture_aspect_ratio = conn_state->picture_aspect_ratio;
Ville Syrjälä28b468a2015-09-08 13:40:48 +03001412
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +03001413 pipe_config->lane_count = 4;
1414
Shashank Sharma15953632017-03-13 16:54:03 +05301415 if (scdc->scrambling.supported && IS_GEMINILAKE(dev_priv)) {
1416 if (scdc->scrambling.low_rates)
1417 pipe_config->hdmi_scrambling = true;
1418
1419 if (pipe_config->port_clock > 340000) {
1420 pipe_config->hdmi_scrambling = true;
1421 pipe_config->hdmi_high_tmds_clock_ratio = true;
1422 }
1423 }
1424
Eric Anholt7d573822009-01-02 13:33:00 -08001425 return true;
1426}
1427
Chris Wilson953ece6972014-09-02 20:04:01 +01001428static void
1429intel_hdmi_unset_edid(struct drm_connector *connector)
Ma Ling9dff6af2009-04-02 13:13:26 +08001430{
Chris Wilsondf0e9242010-09-09 16:20:55 +01001431 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +02001432
Chris Wilsonea5b2132010-08-04 13:50:23 +01001433 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +08001434 intel_hdmi->has_audio = false;
Ville Syrjäläabedc072013-01-17 16:31:31 +02001435 intel_hdmi->rgb_quant_range_selectable = false;
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +08001436
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001437 intel_hdmi->dp_dual_mode.type = DRM_DP_DUAL_MODE_NONE;
1438 intel_hdmi->dp_dual_mode.max_tmds_clock = 0;
1439
Chris Wilson953ece6972014-09-02 20:04:01 +01001440 kfree(to_intel_connector(connector)->detect_edid);
1441 to_intel_connector(connector)->detect_edid = NULL;
Ma Ling9dff6af2009-04-02 13:13:26 +08001442}
1443
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001444static void
Ville Syrjäläd6199252016-05-04 14:45:22 +03001445intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001446{
1447 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1448 struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
Ville Syrjäläd6199252016-05-04 14:45:22 +03001449 enum port port = hdmi_to_dig_port(hdmi)->port;
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001450 struct i2c_adapter *adapter =
1451 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
1452 enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
1453
Ville Syrjäläd6199252016-05-04 14:45:22 +03001454 /*
1455 * Type 1 DVI adaptors are not required to implement any
1456 * registers, so we can't always detect their presence.
1457 * Ideally we should be able to check the state of the
1458 * CONFIG1 pin, but no such luck on our hardware.
1459 *
1460 * The only method left to us is to check the VBT to see
1461 * if the port is a dual mode capable DP port. But let's
1462 * only do that when we sucesfully read the EDID, to avoid
1463 * confusing log messages about DP dual mode adaptors when
1464 * there's nothing connected to the port.
1465 */
1466 if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
1467 if (has_edid &&
1468 intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
1469 DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
1470 type = DRM_DP_DUAL_MODE_TYPE1_DVI;
1471 } else {
1472 type = DRM_DP_DUAL_MODE_NONE;
1473 }
1474 }
1475
1476 if (type == DRM_DP_DUAL_MODE_NONE)
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001477 return;
1478
1479 hdmi->dp_dual_mode.type = type;
1480 hdmi->dp_dual_mode.max_tmds_clock =
1481 drm_dp_dual_mode_max_tmds_clock(type, adapter);
1482
1483 DRM_DEBUG_KMS("DP dual mode adaptor (%s) detected (max TMDS clock: %d kHz)\n",
1484 drm_dp_get_dual_mode_type_name(type),
1485 hdmi->dp_dual_mode.max_tmds_clock);
1486}
1487
Chris Wilson953ece6972014-09-02 20:04:01 +01001488static bool
David Weinehall23f889b2016-08-17 15:47:48 +03001489intel_hdmi_set_edid(struct drm_connector *connector)
Eric Anholt7d573822009-01-02 13:33:00 -08001490{
Chris Wilson953ece6972014-09-02 20:04:01 +01001491 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1492 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
David Weinehall23f889b2016-08-17 15:47:48 +03001493 struct edid *edid;
Chris Wilson953ece6972014-09-02 20:04:01 +01001494 bool connected = false;
Eric Anholt7d573822009-01-02 13:33:00 -08001495
David Weinehall23f889b2016-08-17 15:47:48 +03001496 intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
Imre Deak671dedd2014-03-05 16:20:53 +02001497
David Weinehall23f889b2016-08-17 15:47:48 +03001498 edid = drm_get_edid(connector,
1499 intel_gmbus_get_adapter(dev_priv,
1500 intel_hdmi->ddc_bus));
Imre Deak671dedd2014-03-05 16:20:53 +02001501
David Weinehall23f889b2016-08-17 15:47:48 +03001502 intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001503
David Weinehall23f889b2016-08-17 15:47:48 +03001504 intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
Imre Deak671dedd2014-03-05 16:20:53 +02001505
Chris Wilson953ece6972014-09-02 20:04:01 +01001506 to_intel_connector(connector)->detect_edid = edid;
1507 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL) {
1508 intel_hdmi->rgb_quant_range_selectable =
1509 drm_rgb_quant_range_selectable(edid);
1510
1511 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
1512 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
1513 intel_hdmi->has_audio =
1514 intel_hdmi->force_audio == HDMI_AUDIO_ON;
1515
1516 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
1517 intel_hdmi->has_hdmi_sink =
1518 drm_detect_hdmi_monitor(edid);
1519
1520 connected = true;
1521 }
1522
1523 return connected;
1524}
1525
Daniel Vetter8166fce2015-10-08 21:50:57 +02001526static enum drm_connector_status
1527intel_hdmi_detect(struct drm_connector *connector, bool force)
Chris Wilson953ece6972014-09-02 20:04:01 +01001528{
Daniel Vetter8166fce2015-10-08 21:50:57 +02001529 enum drm_connector_status status;
Daniel Vetter8166fce2015-10-08 21:50:57 +02001530 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Chris Wilson953ece6972014-09-02 20:04:01 +01001531
Daniel Vetter8166fce2015-10-08 21:50:57 +02001532 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1533 connector->base.id, connector->name);
1534
Imre Deak29bb94b2015-11-19 20:55:01 +02001535 intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
1536
Daniel Vetter8166fce2015-10-08 21:50:57 +02001537 intel_hdmi_unset_edid(connector);
Chris Wilson953ece6972014-09-02 20:04:01 +01001538
David Weinehall23f889b2016-08-17 15:47:48 +03001539 if (intel_hdmi_set_edid(connector)) {
Chris Wilson953ece6972014-09-02 20:04:01 +01001540 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1541
1542 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1543 status = connector_status_connected;
Daniel Vetter8166fce2015-10-08 21:50:57 +02001544 } else
Chris Wilson953ece6972014-09-02 20:04:01 +01001545 status = connector_status_disconnected;
1546
Imre Deak29bb94b2015-11-19 20:55:01 +02001547 intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
1548
Chris Wilson953ece6972014-09-02 20:04:01 +01001549 return status;
1550}
1551
1552static void
1553intel_hdmi_force(struct drm_connector *connector)
1554{
1555 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1556
1557 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1558 connector->base.id, connector->name);
1559
1560 intel_hdmi_unset_edid(connector);
1561
1562 if (connector->status != connector_status_connected)
1563 return;
1564
David Weinehall23f889b2016-08-17 15:47:48 +03001565 intel_hdmi_set_edid(connector);
Chris Wilson953ece6972014-09-02 20:04:01 +01001566 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1567}
1568
1569static int intel_hdmi_get_modes(struct drm_connector *connector)
1570{
1571 struct edid *edid;
1572
1573 edid = to_intel_connector(connector)->detect_edid;
1574 if (edid == NULL)
1575 return 0;
1576
1577 return intel_connector_update_modes(connector, edid);
Eric Anholt7d573822009-01-02 13:33:00 -08001578}
1579
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001580static bool
1581intel_hdmi_detect_audio(struct drm_connector *connector)
1582{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001583 bool has_audio = false;
Chris Wilson953ece6972014-09-02 20:04:01 +01001584 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001585
Chris Wilson953ece6972014-09-02 20:04:01 +01001586 edid = to_intel_connector(connector)->detect_edid;
1587 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL)
1588 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02001589
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001590 return has_audio;
1591}
1592
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001593static int
1594intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -03001595 struct drm_property *property,
1596 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001597{
1598 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001599 struct intel_digital_port *intel_dig_port =
1600 hdmi_to_dig_port(intel_hdmi);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001601 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001602 int ret;
1603
Rob Clark662595d2012-10-11 20:36:04 -05001604 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001605 if (ret)
1606 return ret;
1607
Chris Wilson3f43c482011-05-12 22:17:24 +01001608 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001609 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001610 bool has_audio;
1611
1612 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001613 return 0;
1614
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001615 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001616
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001617 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001618 has_audio = intel_hdmi_detect_audio(connector);
1619 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001620 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001621
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001622 if (i == HDMI_AUDIO_OFF_DVI)
1623 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001624
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001625 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001626 goto done;
1627 }
1628
Chris Wilsone953fd72011-02-21 22:23:52 +00001629 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02001630 bool old_auto = intel_hdmi->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001631 bool old_range = intel_hdmi->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02001632
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001633 switch (val) {
1634 case INTEL_BROADCAST_RGB_AUTO:
1635 intel_hdmi->color_range_auto = true;
1636 break;
1637 case INTEL_BROADCAST_RGB_FULL:
1638 intel_hdmi->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001639 intel_hdmi->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001640 break;
1641 case INTEL_BROADCAST_RGB_LIMITED:
1642 intel_hdmi->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001643 intel_hdmi->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001644 break;
1645 default:
1646 return -EINVAL;
1647 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02001648
1649 if (old_auto == intel_hdmi->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001650 old_range == intel_hdmi->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02001651 return 0;
1652
Chris Wilsone953fd72011-02-21 22:23:52 +00001653 goto done;
1654 }
1655
Vandana Kannan94a11dd2014-06-11 11:06:01 +05301656 if (property == connector->dev->mode_config.aspect_ratio_property) {
Maarten Lankhorst0e9f25d2017-05-01 15:37:53 +02001657 connector->state->picture_aspect_ratio = val;
Vandana Kannan94a11dd2014-06-11 11:06:01 +05301658 goto done;
1659 }
1660
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001661 return -EINVAL;
1662
1663done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00001664 if (intel_dig_port->base.base.crtc)
1665 intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001666
1667 return 0;
1668}
1669
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001670static void intel_hdmi_pre_enable(struct intel_encoder *encoder,
1671 struct intel_crtc_state *pipe_config,
1672 struct drm_connector_state *conn_state)
Jesse Barnes13732ba2014-04-05 11:51:35 -07001673{
1674 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001675
Maarten Lankhorstac240282016-11-23 15:57:00 +01001676 intel_hdmi_prepare(encoder, pipe_config);
Daniel Vetter4cde8a22014-04-24 23:54:56 +02001677
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001678 intel_hdmi->set_infoframes(&encoder->base,
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001679 pipe_config->has_hdmi_sink,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001680 pipe_config, conn_state);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001681}
1682
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001683static void vlv_hdmi_pre_enable(struct intel_encoder *encoder,
1684 struct intel_crtc_state *pipe_config,
1685 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001686{
1687 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001688 struct intel_hdmi *intel_hdmi = &dport->hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001689 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001690 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001691
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03001692 vlv_phy_pre_encoder_enable(encoder);
Jani Nikulab76cf762013-07-30 12:20:31 +03001693
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03001694 /* HDMI 1.0V-2dB */
1695 vlv_set_phy_signal_level(encoder, 0x2b245f5f, 0x00002000, 0x5578b83a,
1696 0x2b247878);
1697
Daniel Vetter6897b4b2014-04-24 23:54:47 +02001698 intel_hdmi->set_infoframes(&encoder->base,
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001699 pipe_config->has_hdmi_sink,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001700 pipe_config, conn_state);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001701
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001702 g4x_enable_hdmi(encoder, pipe_config, conn_state);
Jani Nikulab76cf762013-07-30 12:20:31 +03001703
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001704 vlv_wait_port_ready(dev_priv, dport, 0x0);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001705}
1706
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001707static void vlv_hdmi_pre_pll_enable(struct intel_encoder *encoder,
1708 struct intel_crtc_state *pipe_config,
1709 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001710{
Maarten Lankhorstac240282016-11-23 15:57:00 +01001711 intel_hdmi_prepare(encoder, pipe_config);
Daniel Vetter4cde8a22014-04-24 23:54:56 +02001712
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03001713 vlv_phy_pre_pll_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001714}
1715
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001716static void chv_hdmi_pre_pll_enable(struct intel_encoder *encoder,
1717 struct intel_crtc_state *pipe_config,
1718 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03001719{
Maarten Lankhorstac240282016-11-23 15:57:00 +01001720 intel_hdmi_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03001721
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03001722 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03001723}
1724
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001725static void chv_hdmi_post_pll_disable(struct intel_encoder *encoder,
1726 struct intel_crtc_state *old_crtc_state,
1727 struct drm_connector_state *old_conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03001728{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03001729 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03001730}
1731
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001732static void vlv_hdmi_post_disable(struct intel_encoder *encoder,
1733 struct intel_crtc_state *old_crtc_state,
1734 struct drm_connector_state *old_conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001735{
Jesse Barnes89b667f2013-04-18 14:51:36 -07001736 /* Reset lanes to avoid HDMI flicker (VLV w/a) */
Ander Conselvan de Oliveira0f572eb2016-04-27 15:44:25 +03001737 vlv_phy_reset_lanes(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001738}
1739
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001740static void chv_hdmi_post_disable(struct intel_encoder *encoder,
1741 struct intel_crtc_state *old_crtc_state,
1742 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03001743{
Ville Syrjälä580d3812014-04-09 13:29:00 +03001744 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001745 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001746
Ville Syrjäläa5805162015-05-26 20:42:30 +03001747 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001748
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03001749 /* Assert data lane reset */
1750 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001751
Ville Syrjäläa5805162015-05-26 20:42:30 +03001752 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001753}
1754
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001755static void chv_hdmi_pre_enable(struct intel_encoder *encoder,
1756 struct intel_crtc_state *pipe_config,
1757 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001758{
1759 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
Clint Taylorb4eb1562014-11-21 11:13:02 -08001760 struct intel_hdmi *intel_hdmi = &dport->hdmi;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001761 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001762 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001763
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03001764 chv_phy_pre_encoder_enable(encoder);
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03001765
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001766 /* FIXME: Program the support xxx V-dB */
1767 /* Use 800mV-0dB */
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03001768 chv_set_phy_signal_level(encoder, 128, 102, false);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001769
Clint Taylorb4eb1562014-11-21 11:13:02 -08001770 intel_hdmi->set_infoframes(&encoder->base,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001771 pipe_config->has_hdmi_sink,
1772 pipe_config, conn_state);
Clint Taylorb4eb1562014-11-21 11:13:02 -08001773
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001774 g4x_enable_hdmi(encoder, pipe_config, conn_state);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001775
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001776 vlv_wait_port_ready(dev_priv, dport, 0x0);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001777
1778 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03001779 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001780}
1781
Eric Anholt7d573822009-01-02 13:33:00 -08001782static void intel_hdmi_destroy(struct drm_connector *connector)
1783{
Chris Wilson10e972d2014-09-04 21:43:45 +01001784 kfree(to_intel_connector(connector)->detect_edid);
Eric Anholt7d573822009-01-02 13:33:00 -08001785 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +08001786 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001787}
1788
Eric Anholt7d573822009-01-02 13:33:00 -08001789static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02001790 .dpms = drm_atomic_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -08001791 .detect = intel_hdmi_detect,
Chris Wilson953ece6972014-09-02 20:04:01 +01001792 .force = intel_hdmi_force,
Eric Anholt7d573822009-01-02 13:33:00 -08001793 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001794 .set_property = intel_hdmi_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08001795 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01001796 .late_register = intel_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01001797 .early_unregister = intel_connector_unregister,
Eric Anholt7d573822009-01-02 13:33:00 -08001798 .destroy = intel_hdmi_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08001799 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02001800 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Eric Anholt7d573822009-01-02 13:33:00 -08001801};
1802
1803static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
1804 .get_modes = intel_hdmi_get_modes,
1805 .mode_valid = intel_hdmi_mode_valid,
Eric Anholt7d573822009-01-02 13:33:00 -08001806};
1807
Eric Anholt7d573822009-01-02 13:33:00 -08001808static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001809 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -08001810};
1811
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001812static void
1813intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
1814{
Chris Wilson3f43c482011-05-12 22:17:24 +01001815 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00001816 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001817 intel_hdmi->color_range_auto = true;
Vandana Kannan94a11dd2014-06-11 11:06:01 +05301818 intel_attach_aspect_ratio_property(connector);
Maarten Lankhorst0e9f25d2017-05-01 15:37:53 +02001819 connector->state->picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001820}
1821
Shashank Sharma15953632017-03-13 16:54:03 +05301822/*
1823 * intel_hdmi_handle_sink_scrambling: handle sink scrambling/clock ratio setup
1824 * @encoder: intel_encoder
1825 * @connector: drm_connector
1826 * @high_tmds_clock_ratio = bool to indicate if the function needs to set
1827 * or reset the high tmds clock ratio for scrambling
1828 * @scrambling: bool to Indicate if the function needs to set or reset
1829 * sink scrambling
1830 *
1831 * This function handles scrambling on HDMI 2.0 capable sinks.
1832 * If required clock rate is > 340 Mhz && scrambling is supported by sink
1833 * it enables scrambling. This should be called before enabling the HDMI
1834 * 2.0 port, as the sink can choose to disable the scrambling if it doesn't
1835 * detect a scrambled clock within 100 ms.
1836 */
1837void intel_hdmi_handle_sink_scrambling(struct intel_encoder *encoder,
1838 struct drm_connector *connector,
1839 bool high_tmds_clock_ratio,
1840 bool scrambling)
1841{
1842 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1843 struct drm_i915_private *dev_priv = connector->dev->dev_private;
1844 struct drm_scrambling *sink_scrambling =
1845 &connector->display_info.hdmi.scdc.scrambling;
1846 struct i2c_adapter *adptr = intel_gmbus_get_adapter(dev_priv,
1847 intel_hdmi->ddc_bus);
1848 bool ret;
1849
1850 if (!sink_scrambling->supported)
1851 return;
1852
1853 DRM_DEBUG_KMS("Setting sink scrambling for enc:%s connector:%s\n",
1854 encoder->base.name, connector->name);
1855
1856 /* Set TMDS bit clock ratio to 1/40 or 1/10 */
1857 ret = drm_scdc_set_high_tmds_clock_ratio(adptr, high_tmds_clock_ratio);
1858 if (!ret) {
1859 DRM_ERROR("Set TMDS ratio failed\n");
1860 return;
1861 }
1862
1863 /* Enable/disable sink scrambling */
1864 ret = drm_scdc_set_scrambling(adptr, scrambling);
1865 if (!ret) {
1866 DRM_ERROR("Set sink scrambling failed\n");
1867 return;
1868 }
1869
1870 DRM_DEBUG_KMS("sink scrambling handled\n");
1871}
1872
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001873static u8 intel_hdmi_ddc_pin(struct drm_i915_private *dev_priv,
1874 enum port port)
1875{
1876 const struct ddi_vbt_port_info *info =
1877 &dev_priv->vbt.ddi_port_info[port];
1878 u8 ddc_pin;
1879
1880 if (info->alternate_ddc_pin) {
1881 DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (VBT)\n",
1882 info->alternate_ddc_pin, port_name(port));
1883 return info->alternate_ddc_pin;
1884 }
1885
1886 switch (port) {
1887 case PORT_B:
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001888 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001889 ddc_pin = GMBUS_PIN_1_BXT;
1890 else
1891 ddc_pin = GMBUS_PIN_DPB;
1892 break;
1893 case PORT_C:
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001894 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001895 ddc_pin = GMBUS_PIN_2_BXT;
1896 else
1897 ddc_pin = GMBUS_PIN_DPC;
1898 break;
1899 case PORT_D:
1900 if (IS_CHERRYVIEW(dev_priv))
1901 ddc_pin = GMBUS_PIN_DPD_CHV;
1902 else
1903 ddc_pin = GMBUS_PIN_DPD;
1904 break;
1905 default:
1906 MISSING_CASE(port);
1907 ddc_pin = GMBUS_PIN_DPB;
1908 break;
1909 }
1910
1911 DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (platform default)\n",
1912 ddc_pin, port_name(port));
1913
1914 return ddc_pin;
1915}
1916
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001917void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1918 struct intel_connector *intel_connector)
Eric Anholt7d573822009-01-02 13:33:00 -08001919{
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001920 struct drm_connector *connector = &intel_connector->base;
1921 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
1922 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1923 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001924 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02001925 enum port port = intel_dig_port->port;
Eric Anholt7d573822009-01-02 13:33:00 -08001926
Ville Syrjälä22f350422016-06-03 12:17:43 +03001927 DRM_DEBUG_KMS("Adding HDMI connector on port %c\n",
1928 port_name(port));
1929
Ville Syrjäläccb1a832015-12-08 19:59:38 +02001930 if (WARN(intel_dig_port->max_lanes < 4,
1931 "Not enough lanes (%d) for HDMI on port %c\n",
1932 intel_dig_port->max_lanes, port_name(port)))
1933 return;
1934
Eric Anholt7d573822009-01-02 13:33:00 -08001935 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -04001936 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -08001937 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
1938
Peter Rossc3febcc2012-01-28 14:49:26 +01001939 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001940 connector->doublescan_allowed = 0;
Damien Lespiau573e74a2013-09-25 16:45:40 +01001941 connector->stereo_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001942
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001943 intel_hdmi->ddc_bus = intel_hdmi_ddc_pin(dev_priv, port);
1944
Daniel Vetter08d644a2012-07-12 20:19:59 +02001945 switch (port) {
1946 case PORT_B:
Ander Conselvan de Oliveiraca4c3892017-02-03 16:03:13 +02001947 intel_encoder->hpd_pin = HPD_PORT_B;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001948 break;
1949 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05001950 intel_encoder->hpd_pin = HPD_PORT_C;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001951 break;
1952 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05001953 intel_encoder->hpd_pin = HPD_PORT_D;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001954 break;
Xiong Zhang11c1b652015-08-17 16:04:04 +08001955 case PORT_E:
Xiong Zhang11c1b652015-08-17 16:04:04 +08001956 intel_encoder->hpd_pin = HPD_PORT_E;
1957 break;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001958 default:
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001959 MISSING_CASE(port);
1960 return;
Ma Lingf8aed702009-08-24 13:50:24 +08001961 }
Eric Anholt7d573822009-01-02 13:33:00 -08001962
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001963 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Shobhit Kumar90b107c2012-03-28 13:39:32 -07001964 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001965 intel_hdmi->set_infoframes = vlv_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001966 intel_hdmi->infoframe_enabled = vlv_infoframe_enabled;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001967 } else if (IS_G4X(dev_priv)) {
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001968 intel_hdmi->write_infoframe = g4x_write_infoframe;
1969 intel_hdmi->set_infoframes = g4x_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001970 intel_hdmi->infoframe_enabled = g4x_infoframe_enabled;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001971 } else if (HAS_DDI(dev_priv)) {
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -03001972 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001973 intel_hdmi->set_infoframes = hsw_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001974 intel_hdmi->infoframe_enabled = hsw_infoframe_enabled;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001975 } else if (HAS_PCH_IBX(dev_priv)) {
Paulo Zanonifdf12502012-05-04 17:18:24 -03001976 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001977 intel_hdmi->set_infoframes = ibx_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001978 intel_hdmi->infoframe_enabled = ibx_infoframe_enabled;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001979 } else {
1980 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001981 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001982 intel_hdmi->infoframe_enabled = cpt_infoframe_enabled;
Jesse Barnes64a8fc02011-09-22 11:16:00 +05301983 }
Jesse Barnes45187ac2011-08-03 09:22:55 -07001984
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001985 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001986 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
1987 else
1988 intel_connector->get_hw_state = intel_connector_get_hw_state;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001989
1990 intel_hdmi_add_properties(intel_hdmi, connector);
1991
1992 intel_connector_attach_encoder(intel_connector, intel_encoder);
Shashank Sharmad8b4c432015-09-04 18:56:11 +05301993 intel_hdmi->attached_connector = intel_connector;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001994
1995 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1996 * 0xd. Failure to do so will result in spurious interrupts being
1997 * generated on the port when a cable is not attached.
1998 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001999 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002000 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
2001 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
2002 }
2003}
2004
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02002005void intel_hdmi_init(struct drm_i915_private *dev_priv,
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002006 i915_reg_t hdmi_reg, enum port port)
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002007{
2008 struct intel_digital_port *intel_dig_port;
2009 struct intel_encoder *intel_encoder;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002010 struct intel_connector *intel_connector;
2011
Daniel Vetterb14c5672013-09-19 12:18:32 +02002012 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002013 if (!intel_dig_port)
2014 return;
2015
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03002016 intel_connector = intel_connector_alloc();
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002017 if (!intel_connector) {
2018 kfree(intel_dig_port);
2019 return;
2020 }
2021
2022 intel_encoder = &intel_dig_port->base;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002023
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02002024 drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
2025 &intel_hdmi_enc_funcs, DRM_MODE_ENCODER_TMDS,
2026 "HDMI %c", port_name(port));
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002027
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002028 intel_encoder->compute_config = intel_hdmi_compute_config;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002029 if (HAS_PCH_SPLIT(dev_priv)) {
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03002030 intel_encoder->disable = pch_disable_hdmi;
2031 intel_encoder->post_disable = pch_post_disable_hdmi;
2032 } else {
2033 intel_encoder->disable = g4x_disable_hdmi;
2034 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002035 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002036 intel_encoder->get_config = intel_hdmi_get_config;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002037 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03002038 intel_encoder->pre_pll_enable = chv_hdmi_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03002039 intel_encoder->pre_enable = chv_hdmi_pre_enable;
2040 intel_encoder->enable = vlv_enable_hdmi;
Ville Syrjälä580d3812014-04-09 13:29:00 +03002041 intel_encoder->post_disable = chv_hdmi_post_disable;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03002042 intel_encoder->post_pll_disable = chv_hdmi_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01002043 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee9514ac62013-10-16 17:07:41 +08002044 intel_encoder->pre_pll_enable = vlv_hdmi_pre_pll_enable;
2045 intel_encoder->pre_enable = vlv_hdmi_pre_enable;
Jani Nikulab76cf762013-07-30 12:20:31 +03002046 intel_encoder->enable = vlv_enable_hdmi;
Chon Ming Lee9514ac62013-10-16 17:07:41 +08002047 intel_encoder->post_disable = vlv_hdmi_post_disable;
Jani Nikulab76cf762013-07-30 12:20:31 +03002048 } else {
Jesse Barnes13732ba2014-04-05 11:51:35 -07002049 intel_encoder->pre_enable = intel_hdmi_pre_enable;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002050 if (HAS_PCH_CPT(dev_priv))
Ville Syrjäläd1b15892015-05-05 17:06:19 +03002051 intel_encoder->enable = cpt_enable_hdmi;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002052 else if (HAS_PCH_IBX(dev_priv))
Ville Syrjäläbf868c72015-05-05 17:06:23 +03002053 intel_encoder->enable = ibx_enable_hdmi;
Ville Syrjäläd1b15892015-05-05 17:06:19 +03002054 else
Ville Syrjäläbf868c72015-05-05 17:06:23 +03002055 intel_encoder->enable = g4x_enable_hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07002056 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02002057
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002058 intel_encoder->type = INTEL_OUTPUT_HDMI;
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02002059 intel_encoder->power_domain = intel_port_to_power_domain(port);
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07002060 intel_encoder->port = port;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01002061 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03002062 if (port == PORT_D)
2063 intel_encoder->crtc_mask = 1 << 2;
2064 else
2065 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
2066 } else {
2067 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
2068 }
Ville Syrjälä301ea742014-03-03 16:15:30 +02002069 intel_encoder->cloneable = 1 << INTEL_OUTPUT_ANALOG;
Ville Syrjäläc6f14952014-03-03 16:15:31 +02002070 /*
2071 * BSpec is unclear about HDMI+HDMI cloning on g4x, but it seems
2072 * to work on real hardware. And since g4x can send infoframes to
2073 * only one port anyway, nothing is lost by allowing it.
2074 */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01002075 if (IS_G4X(dev_priv))
Ville Syrjäläc6f14952014-03-03 16:15:31 +02002076 intel_encoder->cloneable |= 1 << INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -08002077
Paulo Zanoni174edf12012-10-26 19:05:50 -02002078 intel_dig_port->port = port;
Paulo Zanonib242b7f2013-02-18 19:00:26 -03002079 intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002080 intel_dig_port->dp.output_reg = INVALID_MMIO_REG;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02002081 intel_dig_port->max_lanes = 4;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01002082
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002083 intel_hdmi_init_connector(intel_dig_port, intel_connector);
Eric Anholt7d573822009-01-02 13:33:00 -08002084}