blob: 6c83442e21525bd7c6e095800f458ba8e7501fb2 [file] [log] [blame]
Eric Anholt7d573822009-01-02 13:33:00 -08001/*
2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2009 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Eric Anholt <eric@anholt.net>
26 * Jesse Barnes <jesse.barnes@intel.com>
27 */
28
29#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Eric Anholt7d573822009-01-02 13:33:00 -080031#include <linux/delay.h>
Damien Lespiau178f7362013-08-06 20:32:18 +010032#include <linux/hdmi.h>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
Matt Roperc6f95f22015-01-22 16:50:32 -080034#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drm_crtc.h>
36#include <drm/drm_edid.h>
Eric Anholt7d573822009-01-02 13:33:00 -080037#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010038#include <drm/i915_drm.h>
Eric Anholt7d573822009-01-02 13:33:00 -080039#include "i915_drv.h"
40
Paulo Zanoni30add222012-10-26 19:05:45 -020041static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
42{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020043 return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
Paulo Zanoni30add222012-10-26 19:05:45 -020044}
45
Daniel Vetterafba0182012-06-12 16:36:45 +020046static void
47assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
48{
Paulo Zanoni30add222012-10-26 19:05:45 -020049 struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
Chris Wilsonfac5e232016-07-04 11:34:36 +010050 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterafba0182012-06-12 16:36:45 +020051 uint32_t enabled_bits;
52
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010053 enabled_bits = HAS_DDI(dev_priv) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
Daniel Vetterafba0182012-06-12 16:36:45 +020054
Paulo Zanonib242b7f2013-02-18 19:00:26 -030055 WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits,
Daniel Vetterafba0182012-06-12 16:36:45 +020056 "HDMI port enabled, expecting disabled\n");
57}
58
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -030059struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
Chris Wilsonea5b2132010-08-04 13:50:23 +010060{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020061 struct intel_digital_port *intel_dig_port =
62 container_of(encoder, struct intel_digital_port, base.base);
63 return &intel_dig_port->hdmi;
Chris Wilsonea5b2132010-08-04 13:50:23 +010064}
65
Chris Wilsondf0e9242010-09-09 16:20:55 +010066static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
67{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020068 return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +010069}
70
Damien Lespiau178f7362013-08-06 20:32:18 +010071static u32 g4x_infoframe_index(enum hdmi_infoframe_type type)
David Härdeman3c17fe42010-09-24 21:44:32 +020072{
Damien Lespiau178f7362013-08-06 20:32:18 +010073 switch (type) {
74 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030075 return VIDEO_DIP_SELECT_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010076 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030077 return VIDEO_DIP_SELECT_SPD;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +010078 case HDMI_INFOFRAME_TYPE_VENDOR:
79 return VIDEO_DIP_SELECT_VENDOR;
Jesse Barnes45187ac2011-08-03 09:22:55 -070080 default:
Ville Syrjäläffc85da2015-12-16 18:10:00 +020081 MISSING_CASE(type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030082 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070083 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070084}
85
Damien Lespiau178f7362013-08-06 20:32:18 +010086static u32 g4x_infoframe_enable(enum hdmi_infoframe_type type)
Jesse Barnes45187ac2011-08-03 09:22:55 -070087{
Damien Lespiau178f7362013-08-06 20:32:18 +010088 switch (type) {
89 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030090 return VIDEO_DIP_ENABLE_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010091 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030092 return VIDEO_DIP_ENABLE_SPD;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +010093 case HDMI_INFOFRAME_TYPE_VENDOR:
94 return VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030095 default:
Ville Syrjäläffc85da2015-12-16 18:10:00 +020096 MISSING_CASE(type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030097 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030098 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -030099}
100
Damien Lespiau178f7362013-08-06 20:32:18 +0100101static u32 hsw_infoframe_enable(enum hdmi_infoframe_type type)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300102{
Damien Lespiau178f7362013-08-06 20:32:18 +0100103 switch (type) {
104 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300105 return VIDEO_DIP_ENABLE_AVI_HSW;
Damien Lespiau178f7362013-08-06 20:32:18 +0100106 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300107 return VIDEO_DIP_ENABLE_SPD_HSW;
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100108 case HDMI_INFOFRAME_TYPE_VENDOR:
109 return VIDEO_DIP_ENABLE_VS_HSW;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300110 default:
Ville Syrjäläffc85da2015-12-16 18:10:00 +0200111 MISSING_CASE(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300112 return 0;
113 }
114}
115
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200116static i915_reg_t
117hsw_dip_data_reg(struct drm_i915_private *dev_priv,
118 enum transcoder cpu_transcoder,
119 enum hdmi_infoframe_type type,
120 int i)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300121{
Damien Lespiau178f7362013-08-06 20:32:18 +0100122 switch (type) {
123 case HDMI_INFOFRAME_TYPE_AVI:
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300124 return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder, i);
Damien Lespiau178f7362013-08-06 20:32:18 +0100125 case HDMI_INFOFRAME_TYPE_SPD:
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300126 return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder, i);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100127 case HDMI_INFOFRAME_TYPE_VENDOR:
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300128 return HSW_TVIDEO_DIP_VS_DATA(cpu_transcoder, i);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300129 default:
Ville Syrjäläffc85da2015-12-16 18:10:00 +0200130 MISSING_CASE(type);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200131 return INVALID_MMIO_REG;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300132 }
133}
134
Daniel Vettera3da1df2012-05-08 15:19:06 +0200135static void g4x_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100136 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100137 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200138 const void *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700139{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200140 const uint32_t *data = frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200141 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100142 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300143 u32 val = I915_READ(VIDEO_DIP_CTL);
Damien Lespiau178f7362013-08-06 20:32:18 +0100144 int i;
David Härdeman3c17fe42010-09-24 21:44:32 +0200145
Paulo Zanoni822974a2012-05-28 16:42:51 -0300146 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
147
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300148 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100149 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700150
Damien Lespiau178f7362013-08-06 20:32:18 +0100151 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300152
153 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700154
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300155 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700156 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200157 I915_WRITE(VIDEO_DIP_DATA, *data);
158 data++;
159 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300160 /* Write every possible data byte to force correct ECC calculation. */
161 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
162 I915_WRITE(VIDEO_DIP_DATA, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300163 mmiowb();
David Härdeman3c17fe42010-09-24 21:44:32 +0200164
Damien Lespiau178f7362013-08-06 20:32:18 +0100165 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300166 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200167 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700168
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300169 I915_WRITE(VIDEO_DIP_CTL, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300170 POSTING_READ(VIDEO_DIP_CTL);
David Härdeman3c17fe42010-09-24 21:44:32 +0200171}
172
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200173static bool g4x_infoframe_enabled(struct drm_encoder *encoder,
174 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800175{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200176 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Jesse Barnes89a35ec2014-11-20 13:24:13 -0800177 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Jesse Barnese43823e2014-11-05 14:26:08 -0800178 u32 val = I915_READ(VIDEO_DIP_CTL);
179
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300180 if ((val & VIDEO_DIP_ENABLE) == 0)
181 return false;
Jesse Barnes89a35ec2014-11-20 13:24:13 -0800182
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300183 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
184 return false;
185
186 return val & (VIDEO_DIP_ENABLE_AVI |
187 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
Jesse Barnese43823e2014-11-05 14:26:08 -0800188}
189
Paulo Zanonifdf12502012-05-04 17:18:24 -0300190static void ibx_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100191 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100192 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200193 const void *frame, ssize_t len)
Paulo Zanonifdf12502012-05-04 17:18:24 -0300194{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200195 const uint32_t *data = frame;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300196 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100197 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100198 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200199 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300200 u32 val = I915_READ(reg);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200201 int i;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300202
Paulo Zanoni822974a2012-05-28 16:42:51 -0300203 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
204
Paulo Zanonifdf12502012-05-04 17:18:24 -0300205 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100206 val |= g4x_infoframe_index(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300207
Damien Lespiau178f7362013-08-06 20:32:18 +0100208 val &= ~g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300209
210 I915_WRITE(reg, val);
211
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300212 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300213 for (i = 0; i < len; i += 4) {
214 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
215 data++;
216 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300217 /* Write every possible data byte to force correct ECC calculation. */
218 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
219 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300220 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300221
Damien Lespiau178f7362013-08-06 20:32:18 +0100222 val |= g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300223 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200224 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300225
226 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300227 POSTING_READ(reg);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300228}
229
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200230static bool ibx_infoframe_enabled(struct drm_encoder *encoder,
231 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800232{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200233 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Jani Nikula052f62f2015-04-29 15:30:07 +0300234 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200235 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
236 i915_reg_t reg = TVIDEO_DIP_CTL(pipe);
Jesse Barnese43823e2014-11-05 14:26:08 -0800237 u32 val = I915_READ(reg);
238
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300239 if ((val & VIDEO_DIP_ENABLE) == 0)
240 return false;
Jani Nikula052f62f2015-04-29 15:30:07 +0300241
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300242 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
243 return false;
244
245 return val & (VIDEO_DIP_ENABLE_AVI |
246 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
247 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Jesse Barnese43823e2014-11-05 14:26:08 -0800248}
249
Paulo Zanonifdf12502012-05-04 17:18:24 -0300250static void cpt_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100251 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100252 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200253 const void *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700254{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200255 const uint32_t *data = frame;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700256 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100257 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100258 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200259 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300260 u32 val = I915_READ(reg);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200261 int i;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700262
Paulo Zanoni822974a2012-05-28 16:42:51 -0300263 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
264
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530265 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100266 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700267
Paulo Zanoniecb97852012-05-04 17:18:21 -0300268 /* The DIP control register spec says that we need to update the AVI
269 * infoframe without clearing its enable bit */
Damien Lespiau178f7362013-08-06 20:32:18 +0100270 if (type != HDMI_INFOFRAME_TYPE_AVI)
271 val &= ~g4x_infoframe_enable(type);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300272
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300273 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700274
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300275 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700276 for (i = 0; i < len; i += 4) {
277 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
278 data++;
279 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300280 /* Write every possible data byte to force correct ECC calculation. */
281 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
282 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300283 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700284
Damien Lespiau178f7362013-08-06 20:32:18 +0100285 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300286 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200287 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700288
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300289 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300290 POSTING_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700291}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700292
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200293static bool cpt_infoframe_enabled(struct drm_encoder *encoder,
294 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800295{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200296 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
297 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
298 u32 val = I915_READ(TVIDEO_DIP_CTL(pipe));
Jesse Barnese43823e2014-11-05 14:26:08 -0800299
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300300 if ((val & VIDEO_DIP_ENABLE) == 0)
301 return false;
302
303 return val & (VIDEO_DIP_ENABLE_AVI |
304 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
305 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Jesse Barnese43823e2014-11-05 14:26:08 -0800306}
307
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700308static void vlv_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100309 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100310 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200311 const void *frame, ssize_t len)
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700312{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200313 const uint32_t *data = frame;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700314 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100315 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100316 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200317 i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300318 u32 val = I915_READ(reg);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200319 int i;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700320
Paulo Zanoni822974a2012-05-28 16:42:51 -0300321 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
322
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700323 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100324 val |= g4x_infoframe_index(type);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700325
Damien Lespiau178f7362013-08-06 20:32:18 +0100326 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300327
328 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700329
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300330 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700331 for (i = 0; i < len; i += 4) {
332 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
333 data++;
334 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300335 /* Write every possible data byte to force correct ECC calculation. */
336 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
337 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300338 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700339
Damien Lespiau178f7362013-08-06 20:32:18 +0100340 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300341 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200342 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700343
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300344 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300345 POSTING_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700346}
347
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200348static bool vlv_infoframe_enabled(struct drm_encoder *encoder,
349 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800350{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200351 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Jesse Barnes535afa22015-04-15 16:52:29 -0700352 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200353 enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
354 u32 val = I915_READ(VLV_TVIDEO_DIP_CTL(pipe));
Jesse Barnese43823e2014-11-05 14:26:08 -0800355
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300356 if ((val & VIDEO_DIP_ENABLE) == 0)
357 return false;
Jesse Barnes535afa22015-04-15 16:52:29 -0700358
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300359 if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
360 return false;
361
362 return val & (VIDEO_DIP_ENABLE_AVI |
363 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
364 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Jesse Barnese43823e2014-11-05 14:26:08 -0800365}
366
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300367static void hsw_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100368 const struct intel_crtc_state *crtc_state,
Damien Lespiau178f7362013-08-06 20:32:18 +0100369 enum hdmi_infoframe_type type,
Ville Syrjäläfff63862013-12-10 15:19:08 +0200370 const void *frame, ssize_t len)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300371{
Ville Syrjäläfff63862013-12-10 15:19:08 +0200372 const uint32_t *data = frame;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300373 struct drm_device *dev = encoder->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100374 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100375 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200376 i915_reg_t ctl_reg = HSW_TVIDEO_DIP_CTL(cpu_transcoder);
377 i915_reg_t data_reg;
Damien Lespiau178f7362013-08-06 20:32:18 +0100378 int i;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300379 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300380
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300381 data_reg = hsw_dip_data_reg(dev_priv, cpu_transcoder, type, 0);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300382
Damien Lespiau178f7362013-08-06 20:32:18 +0100383 val &= ~hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300384 I915_WRITE(ctl_reg, val);
385
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300386 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300387 for (i = 0; i < len; i += 4) {
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300388 I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
389 type, i >> 2), *data);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300390 data++;
391 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300392 /* Write every possible data byte to force correct ECC calculation. */
393 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
Ville Syrjälä436c6d42015-09-18 20:03:37 +0300394 I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
395 type, i >> 2), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300396 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300397
Damien Lespiau178f7362013-08-06 20:32:18 +0100398 val |= hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300399 I915_WRITE(ctl_reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300400 POSTING_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300401}
402
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200403static bool hsw_infoframe_enabled(struct drm_encoder *encoder,
404 const struct intel_crtc_state *pipe_config)
Jesse Barnese43823e2014-11-05 14:26:08 -0800405{
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200406 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
407 u32 val = I915_READ(HSW_TVIDEO_DIP_CTL(pipe_config->cpu_transcoder));
Jesse Barnese43823e2014-11-05 14:26:08 -0800408
Ville Syrjäläec1dc602015-05-05 17:06:25 +0300409 return val & (VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
410 VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
411 VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
Jesse Barnese43823e2014-11-05 14:26:08 -0800412}
413
Damien Lespiau5adaea72013-08-06 20:32:19 +0100414/*
415 * The data we write to the DIP data buffer registers is 1 byte bigger than the
416 * HDMI infoframe size because of an ECC/reserved byte at position 3 (starting
417 * at 0). It's also a byte used by DisplayPort so the same DIP registers can be
418 * used for both technologies.
419 *
420 * DW0: Reserved/ECC/DP | HB2 | HB1 | HB0
421 * DW1: DB3 | DB2 | DB1 | DB0
422 * DW2: DB7 | DB6 | DB5 | DB4
423 * DW3: ...
424 *
425 * (HB is Header Byte, DB is Data Byte)
426 *
427 * The hdmi pack() functions don't know about that hardware specific hole so we
428 * trick them by giving an offset into the buffer and moving back the header
429 * bytes by one.
430 */
Damien Lespiau9198ee52013-08-06 20:32:24 +0100431static void intel_write_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100432 const struct intel_crtc_state *crtc_state,
Damien Lespiau9198ee52013-08-06 20:32:24 +0100433 union hdmi_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700434{
435 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Damien Lespiau5adaea72013-08-06 20:32:19 +0100436 uint8_t buffer[VIDEO_DIP_DATA_SIZE];
437 ssize_t len;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700438
Damien Lespiau5adaea72013-08-06 20:32:19 +0100439 /* see comment above for the reason for this offset */
440 len = hdmi_infoframe_pack(frame, buffer + 1, sizeof(buffer) - 1);
441 if (len < 0)
442 return;
443
444 /* Insert the 'hole' (see big comment above) at position 3 */
445 buffer[0] = buffer[1];
446 buffer[1] = buffer[2];
447 buffer[2] = buffer[3];
448 buffer[3] = 0;
449 len++;
450
Maarten Lankhorstac240282016-11-23 15:57:00 +0100451 intel_hdmi->write_infoframe(encoder, crtc_state, frame->any.type, buffer, len);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700452}
453
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300454static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100455 const struct intel_crtc_state *crtc_state)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700456{
Ville Syrjäläabedc072013-01-17 16:31:31 +0200457 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Ville Syrjälä779c4c22017-01-11 14:57:24 +0200458 const struct drm_display_mode *adjusted_mode =
459 &crtc_state->base.adjusted_mode;
Damien Lespiau5adaea72013-08-06 20:32:19 +0100460 union hdmi_infoframe frame;
461 int ret;
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700462
Damien Lespiau5adaea72013-08-06 20:32:19 +0100463 ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
Ville Syrjälä779c4c22017-01-11 14:57:24 +0200464 adjusted_mode);
Damien Lespiau5adaea72013-08-06 20:32:19 +0100465 if (ret < 0) {
466 DRM_ERROR("couldn't fill AVI infoframe\n");
467 return;
468 }
Paulo Zanonic846b612012-04-13 16:31:41 -0300469
Ville Syrjälä779c4c22017-01-11 14:57:24 +0200470 drm_hdmi_avi_infoframe_quant_range(&frame.avi, adjusted_mode,
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +0200471 crtc_state->limited_color_range ?
472 HDMI_QUANTIZATION_RANGE_LIMITED :
473 HDMI_QUANTIZATION_RANGE_FULL,
474 intel_hdmi->rgb_quant_range_selectable);
Ville Syrjäläabedc072013-01-17 16:31:31 +0200475
Maarten Lankhorstac240282016-11-23 15:57:00 +0100476 intel_write_infoframe(encoder, crtc_state, &frame);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700477}
478
Maarten Lankhorstac240282016-11-23 15:57:00 +0100479static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder,
480 const struct intel_crtc_state *crtc_state)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700481{
Damien Lespiau5adaea72013-08-06 20:32:19 +0100482 union hdmi_infoframe frame;
483 int ret;
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700484
Damien Lespiau5adaea72013-08-06 20:32:19 +0100485 ret = hdmi_spd_infoframe_init(&frame.spd, "Intel", "Integrated gfx");
486 if (ret < 0) {
487 DRM_ERROR("couldn't fill SPD infoframe\n");
488 return;
489 }
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700490
Damien Lespiau5adaea72013-08-06 20:32:19 +0100491 frame.spd.sdi = HDMI_SPD_SDI_PC;
492
Maarten Lankhorstac240282016-11-23 15:57:00 +0100493 intel_write_infoframe(encoder, crtc_state, &frame);
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700494}
495
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100496static void
497intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100498 const struct intel_crtc_state *crtc_state)
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100499{
500 union hdmi_infoframe frame;
501 int ret;
502
503 ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100504 &crtc_state->base.adjusted_mode);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100505 if (ret < 0)
506 return;
507
Maarten Lankhorstac240282016-11-23 15:57:00 +0100508 intel_write_infoframe(encoder, crtc_state, &frame);
Lespiau, Damienc8bb75a2013-08-19 16:59:04 +0100509}
510
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300511static void g4x_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200512 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100513 const struct intel_crtc_state *crtc_state,
514 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300515{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100516 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200517 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
518 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200519 i915_reg_t reg = VIDEO_DIP_CTL;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300520 u32 val = I915_READ(reg);
Ville Syrjälä822cdc52014-01-23 23:15:34 +0200521 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300522
Daniel Vetterafba0182012-06-12 16:36:45 +0200523 assert_hdmi_port_disabled(intel_hdmi);
524
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300525 /* If the registers were not initialized yet, they might be zeroes,
526 * which means we're selecting the AVI DIP and we're setting its
527 * frequency to once. This seems to really confuse the HW and make
528 * things stop working (the register spec says the AVI always needs to
529 * be sent every VSync). So here we avoid writing to the register more
530 * than we need and also explicitly select the AVI DIP and explicitly
531 * set its frequency to every VSync. Avoiding to write it twice seems to
532 * be enough to solve the problem, but being defensive shouldn't hurt us
533 * either. */
534 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
535
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200536 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300537 if (!(val & VIDEO_DIP_ENABLE))
538 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300539 if (port != (val & VIDEO_DIP_PORT_MASK)) {
540 DRM_DEBUG_KMS("video DIP still enabled on port %c\n",
541 (val & VIDEO_DIP_PORT_MASK) >> 29);
542 return;
543 }
544 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
545 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300546 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300547 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300548 return;
549 }
550
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300551 if (port != (val & VIDEO_DIP_PORT_MASK)) {
552 if (val & VIDEO_DIP_ENABLE) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300553 DRM_DEBUG_KMS("video DIP already enabled on port %c\n",
554 (val & VIDEO_DIP_PORT_MASK) >> 29);
555 return;
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300556 }
557 val &= ~VIDEO_DIP_PORT_MASK;
558 val |= port;
559 }
560
Paulo Zanoni822974a2012-05-28 16:42:51 -0300561 val |= VIDEO_DIP_ENABLE;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300562 val &= ~(VIDEO_DIP_ENABLE_AVI |
563 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300564
Paulo Zanonif278d972012-05-28 16:42:50 -0300565 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300566 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300567
Maarten Lankhorstac240282016-11-23 15:57:00 +0100568 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
569 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
570 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300571}
572
Maarten Lankhorstac240282016-11-23 15:57:00 +0100573static bool hdmi_sink_is_deep_color(const struct drm_connector_state *conn_state)
Ville Syrjälä6d674152015-05-05 17:06:20 +0300574{
Maarten Lankhorstac240282016-11-23 15:57:00 +0100575 struct drm_connector *connector = conn_state->connector;
Ville Syrjälä6d674152015-05-05 17:06:20 +0300576
577 /*
578 * HDMI cloning is only supported on g4x which doesn't
579 * support deep color or GCP infoframes anyway so no
580 * need to worry about multiple HDMI sinks here.
581 */
Ville Syrjälä6d674152015-05-05 17:06:20 +0300582
Maarten Lankhorstac240282016-11-23 15:57:00 +0100583 return connector->display_info.bpc > 8;
Ville Syrjälä6d674152015-05-05 17:06:20 +0300584}
585
Ville Syrjälä12aa3292015-05-05 17:06:21 +0300586/*
587 * Determine if default_phase=1 can be indicated in the GCP infoframe.
588 *
589 * From HDMI specification 1.4a:
590 * - The first pixel of each Video Data Period shall always have a pixel packing phase of 0
591 * - The first pixel following each Video Data Period shall have a pixel packing phase of 0
592 * - The PP bits shall be constant for all GCPs and will be equal to the last packing phase
593 * - The first pixel following every transition of HSYNC or VSYNC shall have a pixel packing
594 * phase of 0
595 */
596static bool gcp_default_phase_possible(int pipe_bpp,
597 const struct drm_display_mode *mode)
598{
599 unsigned int pixels_per_group;
600
601 switch (pipe_bpp) {
602 case 30:
603 /* 4 pixels in 5 clocks */
604 pixels_per_group = 4;
605 break;
606 case 36:
607 /* 2 pixels in 3 clocks */
608 pixels_per_group = 2;
609 break;
610 case 48:
611 /* 1 pixel in 2 clocks */
612 pixels_per_group = 1;
613 break;
614 default:
615 /* phase information not relevant for 8bpc */
616 return false;
617 }
618
619 return mode->crtc_hdisplay % pixels_per_group == 0 &&
620 mode->crtc_htotal % pixels_per_group == 0 &&
621 mode->crtc_hblank_start % pixels_per_group == 0 &&
622 mode->crtc_hblank_end % pixels_per_group == 0 &&
623 mode->crtc_hsync_start % pixels_per_group == 0 &&
624 mode->crtc_hsync_end % pixels_per_group == 0 &&
625 ((mode->flags & DRM_MODE_FLAG_INTERLACE) == 0 ||
626 mode->crtc_htotal/2 % pixels_per_group == 0);
627}
628
Maarten Lankhorstac240282016-11-23 15:57:00 +0100629static bool intel_hdmi_set_gcp_infoframe(struct drm_encoder *encoder,
630 const struct intel_crtc_state *crtc_state,
631 const struct drm_connector_state *conn_state)
Ville Syrjälä6d674152015-05-05 17:06:20 +0300632{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100633 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100634 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200635 i915_reg_t reg;
636 u32 val = 0;
Ville Syrjälä6d674152015-05-05 17:06:20 +0300637
638 if (HAS_DDI(dev_priv))
Maarten Lankhorstac240282016-11-23 15:57:00 +0100639 reg = HSW_TVIDEO_DIP_GCP(crtc_state->cpu_transcoder);
Wayne Boyer666a4532015-12-09 12:29:35 -0800640 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300641 reg = VLV_TVIDEO_DIP_GCP(crtc->pipe);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +0300642 else if (HAS_PCH_SPLIT(dev_priv))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300643 reg = TVIDEO_DIP_GCP(crtc->pipe);
644 else
645 return false;
646
647 /* Indicate color depth whenever the sink supports deep color */
Maarten Lankhorstac240282016-11-23 15:57:00 +0100648 if (hdmi_sink_is_deep_color(conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300649 val |= GCP_COLOR_INDICATION;
650
Ville Syrjälä12aa3292015-05-05 17:06:21 +0300651 /* Enable default_phase whenever the display mode is suitably aligned */
Maarten Lankhorstac240282016-11-23 15:57:00 +0100652 if (gcp_default_phase_possible(crtc_state->pipe_bpp,
653 &crtc_state->base.adjusted_mode))
Ville Syrjälä12aa3292015-05-05 17:06:21 +0300654 val |= GCP_DEFAULT_PHASE_ENABLE;
655
Ville Syrjälä6d674152015-05-05 17:06:20 +0300656 I915_WRITE(reg, val);
657
658 return val != 0;
659}
660
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300661static void ibx_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200662 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100663 const struct intel_crtc_state *crtc_state,
664 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300665{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100666 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100667 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200668 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
669 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200670 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300671 u32 val = I915_READ(reg);
Ville Syrjälä822cdc52014-01-23 23:15:34 +0200672 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300673
Daniel Vetterafba0182012-06-12 16:36:45 +0200674 assert_hdmi_port_disabled(intel_hdmi);
675
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300676 /* See the big comment in g4x_set_infoframes() */
677 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
678
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200679 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300680 if (!(val & VIDEO_DIP_ENABLE))
681 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300682 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
683 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
684 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300685 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300686 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300687 return;
688 }
689
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300690 if (port != (val & VIDEO_DIP_PORT_MASK)) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300691 WARN(val & VIDEO_DIP_ENABLE,
692 "DIP already enabled on port %c\n",
693 (val & VIDEO_DIP_PORT_MASK) >> 29);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300694 val &= ~VIDEO_DIP_PORT_MASK;
695 val |= port;
696 }
697
Paulo Zanoni822974a2012-05-28 16:42:51 -0300698 val |= VIDEO_DIP_ENABLE;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300699 val &= ~(VIDEO_DIP_ENABLE_AVI |
700 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
701 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300702
Maarten Lankhorstac240282016-11-23 15:57:00 +0100703 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300704 val |= VIDEO_DIP_ENABLE_GCP;
705
Paulo Zanonif278d972012-05-28 16:42:50 -0300706 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300707 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300708
Maarten Lankhorstac240282016-11-23 15:57:00 +0100709 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
710 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
711 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300712}
713
714static void cpt_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200715 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100716 const struct intel_crtc_state *crtc_state,
717 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300718{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100719 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100720 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300721 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200722 i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300723 u32 val = I915_READ(reg);
724
Daniel Vetterafba0182012-06-12 16:36:45 +0200725 assert_hdmi_port_disabled(intel_hdmi);
726
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300727 /* See the big comment in g4x_set_infoframes() */
728 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
729
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200730 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300731 if (!(val & VIDEO_DIP_ENABLE))
732 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300733 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
734 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
735 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300736 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300737 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300738 return;
739 }
740
Paulo Zanoni822974a2012-05-28 16:42:51 -0300741 /* Set both together, unset both together: see the spec. */
742 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300743 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300744 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300745
Maarten Lankhorstac240282016-11-23 15:57:00 +0100746 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300747 val |= VIDEO_DIP_ENABLE_GCP;
748
Paulo Zanoni822974a2012-05-28 16:42:51 -0300749 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300750 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300751
Maarten Lankhorstac240282016-11-23 15:57:00 +0100752 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
753 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
754 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300755}
756
757static void vlv_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200758 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100759 const struct intel_crtc_state *crtc_state,
760 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300761{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100762 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700763 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100764 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300765 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200766 i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300767 u32 val = I915_READ(reg);
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700768 u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300769
Daniel Vetterafba0182012-06-12 16:36:45 +0200770 assert_hdmi_port_disabled(intel_hdmi);
771
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300772 /* See the big comment in g4x_set_infoframes() */
773 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
774
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200775 if (!enable) {
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300776 if (!(val & VIDEO_DIP_ENABLE))
777 return;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300778 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
779 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
780 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300781 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300782 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300783 return;
784 }
785
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700786 if (port != (val & VIDEO_DIP_PORT_MASK)) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300787 WARN(val & VIDEO_DIP_ENABLE,
788 "DIP already enabled on port %c\n",
789 (val & VIDEO_DIP_PORT_MASK) >> 29);
Jesse Barnes6a2b8022014-04-02 10:08:51 -0700790 val &= ~VIDEO_DIP_PORT_MASK;
791 val |= port;
792 }
793
Paulo Zanoni822974a2012-05-28 16:42:51 -0300794 val |= VIDEO_DIP_ENABLE;
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300795 val &= ~(VIDEO_DIP_ENABLE_AVI |
796 VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
797 VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300798
Maarten Lankhorstac240282016-11-23 15:57:00 +0100799 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300800 val |= VIDEO_DIP_ENABLE_GCP;
801
Paulo Zanoni822974a2012-05-28 16:42:51 -0300802 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300803 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300804
Maarten Lankhorstac240282016-11-23 15:57:00 +0100805 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
806 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
807 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300808}
809
810static void hsw_set_infoframes(struct drm_encoder *encoder,
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200811 bool enable,
Maarten Lankhorstac240282016-11-23 15:57:00 +0100812 const struct intel_crtc_state *crtc_state,
813 const struct drm_connector_state *conn_state)
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300814{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100815 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300816 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100817 i915_reg_t reg = HSW_TVIDEO_DIP_CTL(crtc_state->cpu_transcoder);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300818 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300819
Daniel Vetterafba0182012-06-12 16:36:45 +0200820 assert_hdmi_port_disabled(intel_hdmi);
821
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300822 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
823 VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
824 VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
825
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200826 if (!enable) {
Ville Syrjälä0be6f0c2015-05-05 17:06:24 +0300827 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300828 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300829 return;
830 }
831
Maarten Lankhorstac240282016-11-23 15:57:00 +0100832 if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
Ville Syrjälä6d674152015-05-05 17:06:20 +0300833 val |= VIDEO_DIP_ENABLE_GCP_HSW;
834
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300835 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300836 POSTING_READ(reg);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300837
Maarten Lankhorstac240282016-11-23 15:57:00 +0100838 intel_hdmi_set_avi_infoframe(encoder, crtc_state);
839 intel_hdmi_set_spd_infoframe(encoder, crtc_state);
840 intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300841}
842
Ville Syrjäläb2ccb822016-05-02 22:08:24 +0300843void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
844{
845 struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
846 struct i2c_adapter *adapter =
847 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
848
849 if (hdmi->dp_dual_mode.type < DRM_DP_DUAL_MODE_TYPE2_DVI)
850 return;
851
852 DRM_DEBUG_KMS("%s DP dual mode adaptor TMDS output\n",
853 enable ? "Enabling" : "Disabling");
854
855 drm_dp_dual_mode_set_tmds_output(hdmi->dp_dual_mode.type,
856 adapter, enable);
857}
858
Maarten Lankhorstac240282016-11-23 15:57:00 +0100859static void intel_hdmi_prepare(struct intel_encoder *encoder,
860 const struct intel_crtc_state *crtc_state)
Eric Anholt7d573822009-01-02 13:33:00 -0800861{
Daniel Vetterc59423a2013-07-21 21:37:04 +0200862 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100863 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100864 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Daniel Vetterc59423a2013-07-21 21:37:04 +0200865 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Maarten Lankhorstac240282016-11-23 15:57:00 +0100866 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300867 u32 hdmi_val;
Eric Anholt7d573822009-01-02 13:33:00 -0800868
Ville Syrjäläb2ccb822016-05-02 22:08:24 +0300869 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
870
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300871 hdmi_val = SDVO_ENCODING_HDMI;
Maarten Lankhorstac240282016-11-23 15:57:00 +0100872 if (!HAS_PCH_SPLIT(dev_priv) && crtc_state->limited_color_range)
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +0300873 hdmi_val |= HDMI_COLOR_RANGE_16_235;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400874 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300875 hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400876 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300877 hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800878
Maarten Lankhorstac240282016-11-23 15:57:00 +0100879 if (crtc_state->pipe_bpp > 24)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300880 hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700881 else
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300882 hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700883
Maarten Lankhorstac240282016-11-23 15:57:00 +0100884 if (crtc_state->has_hdmi_sink)
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300885 hdmi_val |= HDMI_MODE_SELECT_HDMI;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800886
Tvrtko Ursulin6e266952016-10-13 11:02:53 +0100887 if (HAS_PCH_CPT(dev_priv))
Daniel Vetterc59423a2013-07-21 21:37:04 +0200888 hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100889 else if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee44f37d12014-04-09 13:28:21 +0300890 hdmi_val |= SDVO_PIPE_SEL_CHV(crtc->pipe);
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300891 else
Daniel Vetterc59423a2013-07-21 21:37:04 +0200892 hdmi_val |= SDVO_PIPE_SEL(crtc->pipe);
Eric Anholt7d573822009-01-02 13:33:00 -0800893
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300894 I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
895 POSTING_READ(intel_hdmi->hdmi_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800896}
897
Daniel Vetter85234cd2012-07-02 13:27:29 +0200898static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
899 enum pipe *pipe)
Eric Anholt7d573822009-01-02 13:33:00 -0800900{
Daniel Vetter85234cd2012-07-02 13:27:29 +0200901 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100902 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200903 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Imre Deak6d129be2014-03-05 16:20:54 +0200904 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200905 u32 tmp;
Imre Deak5b092172016-02-12 18:55:20 +0200906 bool ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200907
Imre Deak6d129be2014-03-05 16:20:54 +0200908 power_domain = intel_display_port_power_domain(encoder);
Imre Deak5b092172016-02-12 18:55:20 +0200909 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +0200910 return false;
911
Imre Deak5b092172016-02-12 18:55:20 +0200912 ret = false;
913
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300914 tmp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200915
916 if (!(tmp & SDVO_ENABLE))
Imre Deak5b092172016-02-12 18:55:20 +0200917 goto out;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200918
Tvrtko Ursulin6e266952016-10-13 11:02:53 +0100919 if (HAS_PCH_CPT(dev_priv))
Daniel Vetter85234cd2012-07-02 13:27:29 +0200920 *pipe = PORT_TO_PIPE_CPT(tmp);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100921 else if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä71485e02014-04-09 13:28:55 +0300922 *pipe = SDVO_PORT_TO_PIPE_CHV(tmp);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200923 else
924 *pipe = PORT_TO_PIPE(tmp);
925
Imre Deak5b092172016-02-12 18:55:20 +0200926 ret = true;
927
928out:
929 intel_display_power_put(dev_priv, power_domain);
930
931 return ret;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200932}
933
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700934static void intel_hdmi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200935 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700936{
937 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Ville Syrjälä8c875fc2014-09-12 15:46:29 +0300938 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100939 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700940 u32 tmp, flags = 0;
Ville Syrjälä18442d02013-09-13 16:00:08 +0300941 int dotclock;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700942
943 tmp = I915_READ(intel_hdmi->hdmi_reg);
944
945 if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
946 flags |= DRM_MODE_FLAG_PHSYNC;
947 else
948 flags |= DRM_MODE_FLAG_NHSYNC;
949
950 if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
951 flags |= DRM_MODE_FLAG_PVSYNC;
952 else
953 flags |= DRM_MODE_FLAG_NVSYNC;
954
Daniel Vetter6897b4b52014-04-24 23:54:47 +0200955 if (tmp & HDMI_MODE_SELECT_HDMI)
956 pipe_config->has_hdmi_sink = true;
957
Ville Syrjäläcda0aaa2015-11-26 18:27:07 +0200958 if (intel_hdmi->infoframe_enabled(&encoder->base, pipe_config))
Jesse Barnese43823e2014-11-05 14:26:08 -0800959 pipe_config->has_infoframe = true;
960
Jani Nikulac84db772014-09-17 15:34:58 +0300961 if (tmp & SDVO_AUDIO_ENABLE)
Daniel Vetter9ed109a2014-04-24 23:54:52 +0200962 pipe_config->has_audio = true;
963
Tvrtko Ursulin6e266952016-10-13 11:02:53 +0100964 if (!HAS_PCH_SPLIT(dev_priv) &&
Ville Syrjälä8c875fc2014-09-12 15:46:29 +0300965 tmp & HDMI_COLOR_RANGE_16_235)
966 pipe_config->limited_color_range = true;
967
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200968 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä18442d02013-09-13 16:00:08 +0300969
970 if ((tmp & SDVO_COLOR_FORMAT_MASK) == HDMI_COLOR_FORMAT_12bpc)
971 dotclock = pipe_config->port_clock * 2 / 3;
972 else
973 dotclock = pipe_config->port_clock;
974
Ville Syrjäläbe69a132015-05-05 17:06:26 +0300975 if (pipe_config->pixel_multiplier)
976 dotclock /= pipe_config->pixel_multiplier;
977
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200978 pipe_config->base.adjusted_mode.crtc_clock = dotclock;
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +0300979
980 pipe_config->lane_count = 4;
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700981}
982
Maarten Lankhorstdf18e722016-11-08 13:55:37 +0100983static void intel_enable_hdmi_audio(struct intel_encoder *encoder,
984 struct intel_crtc_state *pipe_config,
985 struct drm_connector_state *conn_state)
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300986{
Maarten Lankhorstac240282016-11-23 15:57:00 +0100987 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300988
Maarten Lankhorstac240282016-11-23 15:57:00 +0100989 WARN_ON(!pipe_config->has_hdmi_sink);
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300990 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
991 pipe_name(crtc->pipe));
Maarten Lankhorstbbf35e92016-11-08 13:55:38 +0100992 intel_audio_codec_enable(encoder, pipe_config, conn_state);
Ville Syrjäläd1b15892015-05-05 17:06:19 +0300993}
994
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +0200995static void g4x_enable_hdmi(struct intel_encoder *encoder,
996 struct intel_crtc_state *pipe_config,
997 struct drm_connector_state *conn_state)
Eric Anholt7d573822009-01-02 13:33:00 -0800998{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200999 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001000 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001001 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Eric Anholt7d573822009-01-02 13:33:00 -08001002 u32 temp;
1003
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001004 temp = I915_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +00001005
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001006 temp |= SDVO_ENABLE;
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001007 if (pipe_config->has_audio)
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001008 temp |= SDVO_AUDIO_ENABLE;
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001009
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001010 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1011 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001012
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001013 if (pipe_config->has_audio)
1014 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001015}
1016
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001017static void ibx_enable_hdmi(struct intel_encoder *encoder,
1018 struct intel_crtc_state *pipe_config,
1019 struct drm_connector_state *conn_state)
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001020{
1021 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001022 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001023 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1024 u32 temp;
1025
1026 temp = I915_READ(intel_hdmi->hdmi_reg);
1027
1028 temp |= SDVO_ENABLE;
Maarten Lankhorstac240282016-11-23 15:57:00 +01001029 if (pipe_config->has_audio)
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001030 temp |= SDVO_AUDIO_ENABLE;
1031
1032 /*
1033 * HW workaround, need to write this twice for issue
1034 * that may result in first write getting masked.
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001035 */
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001036 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1037 POSTING_READ(intel_hdmi->hdmi_reg);
1038 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1039 POSTING_READ(intel_hdmi->hdmi_reg);
1040
1041 /*
1042 * HW workaround, need to toggle enable bit off and on
1043 * for 12bpc with pixel repeat.
1044 *
1045 * FIXME: BSpec says this should be done at the end of
1046 * of the modeset sequence, so not sure if this isn't too soon.
1047 */
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001048 if (pipe_config->pipe_bpp > 24 &&
1049 pipe_config->pixel_multiplier > 1) {
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001050 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
1051 POSTING_READ(intel_hdmi->hdmi_reg);
1052
1053 /*
1054 * HW workaround, need to write this twice for issue
1055 * that may result in first write getting masked.
1056 */
1057 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1058 POSTING_READ(intel_hdmi->hdmi_reg);
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001059 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1060 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001061 }
Jani Nikulac1dec792014-10-27 16:26:56 +02001062
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001063 if (pipe_config->has_audio)
1064 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001065}
1066
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001067static void cpt_enable_hdmi(struct intel_encoder *encoder,
1068 struct intel_crtc_state *pipe_config,
1069 struct drm_connector_state *conn_state)
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001070{
1071 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001072 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstac240282016-11-23 15:57:00 +01001073 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001074 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
1075 enum pipe pipe = crtc->pipe;
1076 u32 temp;
1077
1078 temp = I915_READ(intel_hdmi->hdmi_reg);
1079
1080 temp |= SDVO_ENABLE;
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001081 if (pipe_config->has_audio)
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001082 temp |= SDVO_AUDIO_ENABLE;
1083
1084 /*
1085 * WaEnableHDMI8bpcBefore12bpc:snb,ivb
1086 *
1087 * The procedure for 12bpc is as follows:
1088 * 1. disable HDMI clock gating
1089 * 2. enable HDMI with 8bpc
1090 * 3. enable HDMI with 12bpc
1091 * 4. enable HDMI clock gating
1092 */
1093
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001094 if (pipe_config->pipe_bpp > 24) {
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001095 I915_WRITE(TRANS_CHICKEN1(pipe),
1096 I915_READ(TRANS_CHICKEN1(pipe)) |
1097 TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
1098
1099 temp &= ~SDVO_COLOR_FORMAT_MASK;
1100 temp |= SDVO_COLOR_FORMAT_8bpc;
Jani Nikulac1dec792014-10-27 16:26:56 +02001101 }
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001102
1103 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1104 POSTING_READ(intel_hdmi->hdmi_reg);
1105
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001106 if (pipe_config->pipe_bpp > 24) {
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001107 temp &= ~SDVO_COLOR_FORMAT_MASK;
1108 temp |= HDMI_COLOR_FORMAT_12bpc;
1109
1110 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1111 POSTING_READ(intel_hdmi->hdmi_reg);
1112
1113 I915_WRITE(TRANS_CHICKEN1(pipe),
1114 I915_READ(TRANS_CHICKEN1(pipe)) &
1115 ~TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
1116 }
1117
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001118 if (pipe_config->has_audio)
1119 intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
Jani Nikulab76cf762013-07-30 12:20:31 +03001120}
Jesse Barnes89b667f2013-04-18 14:51:36 -07001121
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001122static void vlv_enable_hdmi(struct intel_encoder *encoder,
1123 struct intel_crtc_state *pipe_config,
1124 struct drm_connector_state *conn_state)
Jani Nikulab76cf762013-07-30 12:20:31 +03001125{
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001126}
1127
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001128static void intel_disable_hdmi(struct intel_encoder *encoder,
1129 struct intel_crtc_state *old_crtc_state,
1130 struct drm_connector_state *old_conn_state)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001131{
1132 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001133 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001134 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Maarten Lankhorstac240282016-11-23 15:57:00 +01001135 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001136 u32 temp;
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001137
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001138 temp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001139
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001140 temp &= ~(SDVO_ENABLE | SDVO_AUDIO_ENABLE);
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001141 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1142 POSTING_READ(intel_hdmi->hdmi_reg);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001143
1144 /*
1145 * HW workaround for IBX, we need to move the port
1146 * to transcoder A after disabling it to allow the
1147 * matching DP port to be enabled on transcoder A.
1148 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001149 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B) {
Ville Syrjälä0c241d52015-10-30 19:23:22 +02001150 /*
1151 * We get CPU/PCH FIFO underruns on the other pipe when
1152 * doing the workaround. Sweep them under the rug.
1153 */
1154 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1155 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
1156
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001157 temp &= ~SDVO_PIPE_B_SELECT;
1158 temp |= SDVO_ENABLE;
1159 /*
1160 * HW workaround, need to write this twice for issue
1161 * that may result in first write getting masked.
1162 */
1163 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1164 POSTING_READ(intel_hdmi->hdmi_reg);
1165 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1166 POSTING_READ(intel_hdmi->hdmi_reg);
1167
1168 temp &= ~SDVO_ENABLE;
1169 I915_WRITE(intel_hdmi->hdmi_reg, temp);
1170 POSTING_READ(intel_hdmi->hdmi_reg);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02001171
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02001172 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
Ville Syrjälä0c241d52015-10-30 19:23:22 +02001173 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
1174 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
Ville Syrjälä1612c8b2015-05-05 17:17:34 +03001175 }
Ville Syrjälä6d674152015-05-05 17:06:20 +03001176
Maarten Lankhorstac240282016-11-23 15:57:00 +01001177 intel_hdmi->set_infoframes(&encoder->base, false, old_crtc_state, old_conn_state);
Ville Syrjäläb2ccb822016-05-02 22:08:24 +03001178
1179 intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
Eric Anholt7d573822009-01-02 13:33:00 -08001180}
1181
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001182static void g4x_disable_hdmi(struct intel_encoder *encoder,
1183 struct intel_crtc_state *old_crtc_state,
1184 struct drm_connector_state *old_conn_state)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001185{
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001186 if (old_crtc_state->has_audio)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001187 intel_audio_codec_disable(encoder);
1188
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001189 intel_disable_hdmi(encoder, old_crtc_state, old_conn_state);
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001190}
1191
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001192static void pch_disable_hdmi(struct intel_encoder *encoder,
1193 struct intel_crtc_state *old_crtc_state,
1194 struct drm_connector_state *old_conn_state)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001195{
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001196 if (old_crtc_state->has_audio)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001197 intel_audio_codec_disable(encoder);
1198}
1199
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001200static void pch_post_disable_hdmi(struct intel_encoder *encoder,
1201 struct intel_crtc_state *old_crtc_state,
1202 struct drm_connector_state *old_conn_state)
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001203{
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001204 intel_disable_hdmi(encoder, old_crtc_state, old_conn_state);
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001205}
1206
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001207static int intel_hdmi_source_max_tmds_clock(struct drm_i915_private *dev_priv)
Daniel Vetter7d148ef2013-07-22 18:02:39 +02001208{
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001209 if (IS_G4X(dev_priv))
Daniel Vetter7d148ef2013-07-22 18:02:39 +02001210 return 165000;
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001211 else if (IS_HASWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 8)
Daniel Vetter7d148ef2013-07-22 18:02:39 +02001212 return 300000;
1213 else
1214 return 225000;
1215}
1216
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001217static int hdmi_port_clock_limit(struct intel_hdmi *hdmi,
1218 bool respect_downstream_limits)
1219{
1220 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
1221 int max_tmds_clock = intel_hdmi_source_max_tmds_clock(to_i915(dev));
1222
1223 if (respect_downstream_limits) {
Ville Syrjälä8cadab02016-09-28 16:51:43 +03001224 struct intel_connector *connector = hdmi->attached_connector;
1225 const struct drm_display_info *info = &connector->base.display_info;
1226
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001227 if (hdmi->dp_dual_mode.max_tmds_clock)
1228 max_tmds_clock = min(max_tmds_clock,
1229 hdmi->dp_dual_mode.max_tmds_clock);
Ville Syrjälä8cadab02016-09-28 16:51:43 +03001230
1231 if (info->max_tmds_clock)
1232 max_tmds_clock = min(max_tmds_clock,
1233 info->max_tmds_clock);
1234 else if (!hdmi->has_hdmi_sink)
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001235 max_tmds_clock = min(max_tmds_clock, 165000);
1236 }
1237
1238 return max_tmds_clock;
1239}
1240
Damien Lespiauc19de8e2013-11-28 15:29:18 +00001241static enum drm_mode_status
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001242hdmi_port_clock_valid(struct intel_hdmi *hdmi,
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001243 int clock, bool respect_downstream_limits)
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001244{
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01001245 struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001246
1247 if (clock < 25000)
1248 return MODE_CLOCK_LOW;
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001249 if (clock > hdmi_port_clock_limit(hdmi, respect_downstream_limits))
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001250 return MODE_CLOCK_HIGH;
1251
Ville Syrjälä5e6ccc02015-07-06 14:44:11 +03001252 /* BXT DPLL can't generate 223-240 MHz */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001253 if (IS_GEN9_LP(dev_priv) && clock > 223333 && clock < 240000)
Ville Syrjälä5e6ccc02015-07-06 14:44:11 +03001254 return MODE_CLOCK_RANGE;
1255
1256 /* CHV DPLL can't generate 216-240 MHz */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +01001257 if (IS_CHERRYVIEW(dev_priv) && clock > 216000 && clock < 240000)
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001258 return MODE_CLOCK_RANGE;
1259
1260 return MODE_OK;
1261}
1262
1263static enum drm_mode_status
Damien Lespiauc19de8e2013-11-28 15:29:18 +00001264intel_hdmi_mode_valid(struct drm_connector *connector,
1265 struct drm_display_mode *mode)
Eric Anholt7d573822009-01-02 13:33:00 -08001266{
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001267 struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
1268 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001269 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001270 enum drm_mode_status status;
1271 int clock;
Mika Kahola587bf492016-02-02 15:16:39 +02001272 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
Eric Anholt7d573822009-01-02 13:33:00 -08001273
1274 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1275 return MODE_NO_DBLESCAN;
1276
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001277 clock = mode->clock;
Mika Kahola587bf492016-02-02 15:16:39 +02001278
1279 if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
1280 clock *= 2;
1281
1282 if (clock > max_dotclk)
1283 return MODE_CLOCK_HIGH;
1284
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001285 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
1286 clock *= 2;
1287
1288 /* check if we can do 8bpc */
1289 status = hdmi_port_clock_valid(hdmi, clock, true);
1290
1291 /* if we can't do 8bpc we may still be able to do 12bpc */
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001292 if (!HAS_GMCH_DISPLAY(dev_priv) && status != MODE_OK)
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001293 status = hdmi_port_clock_valid(hdmi, clock * 3 / 2, true);
1294
1295 return status;
Eric Anholt7d573822009-01-02 13:33:00 -08001296}
1297
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +02001298static bool hdmi_12bpc_possible(struct intel_crtc_state *crtc_state)
Ville Syrjälä71800632014-03-03 16:15:29 +02001299{
Ander Conselvan de Oliveira77f06c82015-03-20 16:18:11 +02001300 struct drm_device *dev = crtc_state->base.crtc->dev;
Ville Syrjälä71800632014-03-03 16:15:29 +02001301
Tvrtko Ursulin49cff962016-10-13 11:02:54 +01001302 if (HAS_GMCH_DISPLAY(to_i915(dev)))
Ville Syrjälä71800632014-03-03 16:15:29 +02001303 return false;
1304
Ville Syrjälä71800632014-03-03 16:15:29 +02001305 /*
1306 * HDMI 12bpc affects the clocks, so it's only possible
1307 * when not cloning with other encoder types.
1308 */
Ville Syrjälä3f1c9282016-06-22 21:57:08 +03001309 return crtc_state->output_types == 1 << INTEL_OUTPUT_HDMI;
Ville Syrjälä71800632014-03-03 16:15:29 +02001310}
1311
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001312bool intel_hdmi_compute_config(struct intel_encoder *encoder,
Maarten Lankhorst0a478c22016-08-09 17:04:05 +02001313 struct intel_crtc_state *pipe_config,
1314 struct drm_connector_state *conn_state)
Eric Anholt7d573822009-01-02 13:33:00 -08001315{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001316 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001317 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02001318 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001319 int clock_8bpc = pipe_config->base.adjusted_mode.crtc_clock;
1320 int clock_12bpc = clock_8bpc * 3 / 2;
Daniel Vettere29c22c2013-02-21 00:00:16 +01001321 int desired_bpp;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02001322
Daniel Vetter6897b4b52014-04-24 23:54:47 +02001323 pipe_config->has_hdmi_sink = intel_hdmi->has_hdmi_sink;
1324
Jesse Barnese43823e2014-11-05 14:26:08 -08001325 if (pipe_config->has_hdmi_sink)
1326 pipe_config->has_infoframe = true;
1327
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001328 if (intel_hdmi->color_range_auto) {
1329 /* See CEA-861-E - 5.1 Default Encoding Parameters */
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001330 pipe_config->limited_color_range =
1331 pipe_config->has_hdmi_sink &&
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02001332 drm_default_rgb_quant_range(adjusted_mode) ==
1333 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001334 } else {
1335 pipe_config->limited_color_range =
1336 intel_hdmi->limited_color_range;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001337 }
1338
Clint Taylor697c4072014-09-02 17:03:36 -07001339 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) {
1340 pipe_config->pixel_multiplier = 2;
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001341 clock_8bpc *= 2;
Ville Syrjälä3320e372015-05-05 17:06:27 +03001342 clock_12bpc *= 2;
Clint Taylor697c4072014-09-02 17:03:36 -07001343 }
1344
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001345 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv))
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001346 pipe_config->has_pch_encoder = true;
1347
Daniel Vetter9ed109a2014-04-24 23:54:52 +02001348 if (pipe_config->has_hdmi_sink && intel_hdmi->has_audio)
1349 pipe_config->has_audio = true;
1350
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001351 /*
1352 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
1353 * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
Daniel Vetter325b9d02013-04-19 11:24:33 +02001354 * outputs. We also need to check that the higher clock still fits
1355 * within limits.
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001356 */
Daniel Vetter6897b4b52014-04-24 23:54:47 +02001357 if (pipe_config->pipe_bpp > 8*3 && pipe_config->has_hdmi_sink &&
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001358 hdmi_port_clock_valid(intel_hdmi, clock_12bpc, true) == MODE_OK &&
Ville Syrjälä7a0baa62015-06-30 15:33:54 +03001359 hdmi_12bpc_possible(pipe_config)) {
Daniel Vettere29c22c2013-02-21 00:00:16 +01001360 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
1361 desired_bpp = 12*3;
Daniel Vetter325b9d02013-04-19 11:24:33 +02001362
1363 /* Need to adjust the port link by 1.5x for 12bpc. */
Daniel Vetterff9a6752013-06-01 17:16:21 +02001364 pipe_config->port_clock = clock_12bpc;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001365 } else {
Daniel Vettere29c22c2013-02-21 00:00:16 +01001366 DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
1367 desired_bpp = 8*3;
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001368
1369 pipe_config->port_clock = clock_8bpc;
Daniel Vettere29c22c2013-02-21 00:00:16 +01001370 }
1371
1372 if (!pipe_config->bw_constrained) {
1373 DRM_DEBUG_KMS("forcing pipe bpc to %i for HDMI\n", desired_bpp);
1374 pipe_config->pipe_bpp = desired_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001375 }
1376
Ville Syrjäläe64e7392015-06-30 19:23:59 +03001377 if (hdmi_port_clock_valid(intel_hdmi, pipe_config->port_clock,
1378 false) != MODE_OK) {
1379 DRM_DEBUG_KMS("unsupported HDMI clock, rejecting mode\n");
Daniel Vetter325b9d02013-04-19 11:24:33 +02001380 return false;
1381 }
1382
Ville Syrjälä28b468a2015-09-08 13:40:48 +03001383 /* Set user selected PAR to incoming mode's member */
1384 adjusted_mode->picture_aspect_ratio = intel_hdmi->aspect_ratio;
1385
Ander Conselvan de Oliveirad4d62792016-04-27 15:44:16 +03001386 pipe_config->lane_count = 4;
1387
Eric Anholt7d573822009-01-02 13:33:00 -08001388 return true;
1389}
1390
Chris Wilson953ece6972014-09-02 20:04:01 +01001391static void
1392intel_hdmi_unset_edid(struct drm_connector *connector)
Ma Ling9dff6af2009-04-02 13:13:26 +08001393{
Chris Wilsondf0e9242010-09-09 16:20:55 +01001394 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Imre Deak671dedd2014-03-05 16:20:53 +02001395
Chris Wilsonea5b2132010-08-04 13:50:23 +01001396 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +08001397 intel_hdmi->has_audio = false;
Ville Syrjäläabedc072013-01-17 16:31:31 +02001398 intel_hdmi->rgb_quant_range_selectable = false;
ling.ma@intel.com2ded9e2742009-07-16 17:23:09 +08001399
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001400 intel_hdmi->dp_dual_mode.type = DRM_DP_DUAL_MODE_NONE;
1401 intel_hdmi->dp_dual_mode.max_tmds_clock = 0;
1402
Chris Wilson953ece6972014-09-02 20:04:01 +01001403 kfree(to_intel_connector(connector)->detect_edid);
1404 to_intel_connector(connector)->detect_edid = NULL;
Ma Ling9dff6af2009-04-02 13:13:26 +08001405}
1406
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001407static void
Ville Syrjäläd6199252016-05-04 14:45:22 +03001408intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001409{
1410 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1411 struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
Ville Syrjäläd6199252016-05-04 14:45:22 +03001412 enum port port = hdmi_to_dig_port(hdmi)->port;
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001413 struct i2c_adapter *adapter =
1414 intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
1415 enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
1416
Ville Syrjäläd6199252016-05-04 14:45:22 +03001417 /*
1418 * Type 1 DVI adaptors are not required to implement any
1419 * registers, so we can't always detect their presence.
1420 * Ideally we should be able to check the state of the
1421 * CONFIG1 pin, but no such luck on our hardware.
1422 *
1423 * The only method left to us is to check the VBT to see
1424 * if the port is a dual mode capable DP port. But let's
1425 * only do that when we sucesfully read the EDID, to avoid
1426 * confusing log messages about DP dual mode adaptors when
1427 * there's nothing connected to the port.
1428 */
1429 if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
1430 if (has_edid &&
1431 intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
1432 DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
1433 type = DRM_DP_DUAL_MODE_TYPE1_DVI;
1434 } else {
1435 type = DRM_DP_DUAL_MODE_NONE;
1436 }
1437 }
1438
1439 if (type == DRM_DP_DUAL_MODE_NONE)
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001440 return;
1441
1442 hdmi->dp_dual_mode.type = type;
1443 hdmi->dp_dual_mode.max_tmds_clock =
1444 drm_dp_dual_mode_max_tmds_clock(type, adapter);
1445
1446 DRM_DEBUG_KMS("DP dual mode adaptor (%s) detected (max TMDS clock: %d kHz)\n",
1447 drm_dp_get_dual_mode_type_name(type),
1448 hdmi->dp_dual_mode.max_tmds_clock);
1449}
1450
Chris Wilson953ece6972014-09-02 20:04:01 +01001451static bool
David Weinehall23f889b2016-08-17 15:47:48 +03001452intel_hdmi_set_edid(struct drm_connector *connector)
Eric Anholt7d573822009-01-02 13:33:00 -08001453{
Chris Wilson953ece6972014-09-02 20:04:01 +01001454 struct drm_i915_private *dev_priv = to_i915(connector->dev);
1455 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
David Weinehall23f889b2016-08-17 15:47:48 +03001456 struct edid *edid;
Chris Wilson953ece6972014-09-02 20:04:01 +01001457 bool connected = false;
Eric Anholt7d573822009-01-02 13:33:00 -08001458
David Weinehall23f889b2016-08-17 15:47:48 +03001459 intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
Imre Deak671dedd2014-03-05 16:20:53 +02001460
David Weinehall23f889b2016-08-17 15:47:48 +03001461 edid = drm_get_edid(connector,
1462 intel_gmbus_get_adapter(dev_priv,
1463 intel_hdmi->ddc_bus));
Imre Deak671dedd2014-03-05 16:20:53 +02001464
David Weinehall23f889b2016-08-17 15:47:48 +03001465 intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
Ville Syrjäläb1ba1242016-05-02 22:08:23 +03001466
David Weinehall23f889b2016-08-17 15:47:48 +03001467 intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
Imre Deak671dedd2014-03-05 16:20:53 +02001468
Chris Wilson953ece6972014-09-02 20:04:01 +01001469 to_intel_connector(connector)->detect_edid = edid;
1470 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL) {
1471 intel_hdmi->rgb_quant_range_selectable =
1472 drm_rgb_quant_range_selectable(edid);
1473
1474 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
1475 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
1476 intel_hdmi->has_audio =
1477 intel_hdmi->force_audio == HDMI_AUDIO_ON;
1478
1479 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
1480 intel_hdmi->has_hdmi_sink =
1481 drm_detect_hdmi_monitor(edid);
1482
1483 connected = true;
1484 }
1485
1486 return connected;
1487}
1488
Daniel Vetter8166fce2015-10-08 21:50:57 +02001489static enum drm_connector_status
1490intel_hdmi_detect(struct drm_connector *connector, bool force)
Chris Wilson953ece6972014-09-02 20:04:01 +01001491{
Daniel Vetter8166fce2015-10-08 21:50:57 +02001492 enum drm_connector_status status;
Daniel Vetter8166fce2015-10-08 21:50:57 +02001493 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Chris Wilson953ece6972014-09-02 20:04:01 +01001494
Daniel Vetter8166fce2015-10-08 21:50:57 +02001495 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1496 connector->base.id, connector->name);
1497
Imre Deak29bb94b2015-11-19 20:55:01 +02001498 intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
1499
Daniel Vetter8166fce2015-10-08 21:50:57 +02001500 intel_hdmi_unset_edid(connector);
Chris Wilson953ece6972014-09-02 20:04:01 +01001501
David Weinehall23f889b2016-08-17 15:47:48 +03001502 if (intel_hdmi_set_edid(connector)) {
Chris Wilson953ece6972014-09-02 20:04:01 +01001503 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1504
1505 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1506 status = connector_status_connected;
Daniel Vetter8166fce2015-10-08 21:50:57 +02001507 } else
Chris Wilson953ece6972014-09-02 20:04:01 +01001508 status = connector_status_disconnected;
1509
Imre Deak29bb94b2015-11-19 20:55:01 +02001510 intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
1511
Chris Wilson953ece6972014-09-02 20:04:01 +01001512 return status;
1513}
1514
1515static void
1516intel_hdmi_force(struct drm_connector *connector)
1517{
1518 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
1519
1520 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1521 connector->base.id, connector->name);
1522
1523 intel_hdmi_unset_edid(connector);
1524
1525 if (connector->status != connector_status_connected)
1526 return;
1527
David Weinehall23f889b2016-08-17 15:47:48 +03001528 intel_hdmi_set_edid(connector);
Chris Wilson953ece6972014-09-02 20:04:01 +01001529 hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
1530}
1531
1532static int intel_hdmi_get_modes(struct drm_connector *connector)
1533{
1534 struct edid *edid;
1535
1536 edid = to_intel_connector(connector)->detect_edid;
1537 if (edid == NULL)
1538 return 0;
1539
1540 return intel_connector_update_modes(connector, edid);
Eric Anholt7d573822009-01-02 13:33:00 -08001541}
1542
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001543static bool
1544intel_hdmi_detect_audio(struct drm_connector *connector)
1545{
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001546 bool has_audio = false;
Chris Wilson953ece6972014-09-02 20:04:01 +01001547 struct edid *edid;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001548
Chris Wilson953ece6972014-09-02 20:04:01 +01001549 edid = to_intel_connector(connector)->detect_edid;
1550 if (edid && edid->input & DRM_EDID_INPUT_DIGITAL)
1551 has_audio = drm_detect_monitor_audio(edid);
Imre Deak671dedd2014-03-05 16:20:53 +02001552
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001553 return has_audio;
1554}
1555
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001556static int
1557intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -03001558 struct drm_property *property,
1559 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001560{
1561 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -02001562 struct intel_digital_port *intel_dig_port =
1563 hdmi_to_dig_port(intel_hdmi);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001564 struct drm_i915_private *dev_priv = to_i915(connector->dev);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001565 int ret;
1566
Rob Clark662595d2012-10-11 20:36:04 -05001567 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001568 if (ret)
1569 return ret;
1570
Chris Wilson3f43c482011-05-12 22:17:24 +01001571 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001572 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001573 bool has_audio;
1574
1575 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001576 return 0;
1577
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001578 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001579
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001580 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001581 has_audio = intel_hdmi_detect_audio(connector);
1582 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001583 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001584
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +08001585 if (i == HDMI_AUDIO_OFF_DVI)
1586 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001587
Chris Wilson1aad7ac2011-02-09 18:46:58 +00001588 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001589 goto done;
1590 }
1591
Chris Wilsone953fd72011-02-21 22:23:52 +00001592 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02001593 bool old_auto = intel_hdmi->color_range_auto;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001594 bool old_range = intel_hdmi->limited_color_range;
Daniel Vetterae4edb82013-04-22 17:07:23 +02001595
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001596 switch (val) {
1597 case INTEL_BROADCAST_RGB_AUTO:
1598 intel_hdmi->color_range_auto = true;
1599 break;
1600 case INTEL_BROADCAST_RGB_FULL:
1601 intel_hdmi->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001602 intel_hdmi->limited_color_range = false;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001603 break;
1604 case INTEL_BROADCAST_RGB_LIMITED:
1605 intel_hdmi->color_range_auto = false;
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001606 intel_hdmi->limited_color_range = true;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001607 break;
1608 default:
1609 return -EINVAL;
1610 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02001611
1612 if (old_auto == intel_hdmi->color_range_auto &&
Ville Syrjälä0f2a2a72015-07-06 15:10:00 +03001613 old_range == intel_hdmi->limited_color_range)
Daniel Vetterae4edb82013-04-22 17:07:23 +02001614 return 0;
1615
Chris Wilsone953fd72011-02-21 22:23:52 +00001616 goto done;
1617 }
1618
Vandana Kannan94a11dd2014-06-11 11:06:01 +05301619 if (property == connector->dev->mode_config.aspect_ratio_property) {
1620 switch (val) {
1621 case DRM_MODE_PICTURE_ASPECT_NONE:
1622 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
1623 break;
1624 case DRM_MODE_PICTURE_ASPECT_4_3:
1625 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_4_3;
1626 break;
1627 case DRM_MODE_PICTURE_ASPECT_16_9:
1628 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_16_9;
1629 break;
1630 default:
1631 return -EINVAL;
1632 }
1633 goto done;
1634 }
1635
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001636 return -EINVAL;
1637
1638done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00001639 if (intel_dig_port->base.base.crtc)
1640 intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001641
1642 return 0;
1643}
1644
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001645static void intel_hdmi_pre_enable(struct intel_encoder *encoder,
1646 struct intel_crtc_state *pipe_config,
1647 struct drm_connector_state *conn_state)
Jesse Barnes13732ba2014-04-05 11:51:35 -07001648{
1649 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001650
Maarten Lankhorstac240282016-11-23 15:57:00 +01001651 intel_hdmi_prepare(encoder, pipe_config);
Daniel Vetter4cde8a22014-04-24 23:54:56 +02001652
Daniel Vetter6897b4b52014-04-24 23:54:47 +02001653 intel_hdmi->set_infoframes(&encoder->base,
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001654 pipe_config->has_hdmi_sink,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001655 pipe_config, conn_state);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001656}
1657
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001658static void vlv_hdmi_pre_enable(struct intel_encoder *encoder,
1659 struct intel_crtc_state *pipe_config,
1660 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001661{
1662 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001663 struct intel_hdmi *intel_hdmi = &dport->hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001664 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001665 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001666
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03001667 vlv_phy_pre_encoder_enable(encoder);
Jani Nikulab76cf762013-07-30 12:20:31 +03001668
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +03001669 /* HDMI 1.0V-2dB */
1670 vlv_set_phy_signal_level(encoder, 0x2b245f5f, 0x00002000, 0x5578b83a,
1671 0x2b247878);
1672
Daniel Vetter6897b4b52014-04-24 23:54:47 +02001673 intel_hdmi->set_infoframes(&encoder->base,
Maarten Lankhorstdf18e722016-11-08 13:55:37 +01001674 pipe_config->has_hdmi_sink,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001675 pipe_config, conn_state);
Jesse Barnes13732ba2014-04-05 11:51:35 -07001676
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001677 g4x_enable_hdmi(encoder, pipe_config, conn_state);
Jani Nikulab76cf762013-07-30 12:20:31 +03001678
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001679 vlv_wait_port_ready(dev_priv, dport, 0x0);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001680}
1681
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001682static void vlv_hdmi_pre_pll_enable(struct intel_encoder *encoder,
1683 struct intel_crtc_state *pipe_config,
1684 struct drm_connector_state *conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001685{
Maarten Lankhorstac240282016-11-23 15:57:00 +01001686 intel_hdmi_prepare(encoder, pipe_config);
Daniel Vetter4cde8a22014-04-24 23:54:56 +02001687
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03001688 vlv_phy_pre_pll_enable(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001689}
1690
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001691static void chv_hdmi_pre_pll_enable(struct intel_encoder *encoder,
1692 struct intel_crtc_state *pipe_config,
1693 struct drm_connector_state *conn_state)
Ville Syrjälä9197c882014-04-09 13:29:05 +03001694{
Maarten Lankhorstac240282016-11-23 15:57:00 +01001695 intel_hdmi_prepare(encoder, pipe_config);
Ville Syrjälä625695f2014-06-28 02:04:02 +03001696
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +03001697 chv_phy_pre_pll_enable(encoder);
Ville Syrjälä9197c882014-04-09 13:29:05 +03001698}
1699
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001700static void chv_hdmi_post_pll_disable(struct intel_encoder *encoder,
1701 struct intel_crtc_state *old_crtc_state,
1702 struct drm_connector_state *old_conn_state)
Ville Syrjäläd6db9952015-07-08 23:45:49 +03001703{
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +03001704 chv_phy_post_pll_disable(encoder);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03001705}
1706
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001707static void vlv_hdmi_post_disable(struct intel_encoder *encoder,
1708 struct intel_crtc_state *old_crtc_state,
1709 struct drm_connector_state *old_conn_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001710{
Jesse Barnes89b667f2013-04-18 14:51:36 -07001711 /* Reset lanes to avoid HDMI flicker (VLV w/a) */
Ander Conselvan de Oliveira0f572eb2016-04-27 15:44:25 +03001712 vlv_phy_reset_lanes(encoder);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001713}
1714
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001715static void chv_hdmi_post_disable(struct intel_encoder *encoder,
1716 struct intel_crtc_state *old_crtc_state,
1717 struct drm_connector_state *old_conn_state)
Ville Syrjälä580d3812014-04-09 13:29:00 +03001718{
Ville Syrjälä580d3812014-04-09 13:29:00 +03001719 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001720 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001721
Ville Syrjäläa5805162015-05-26 20:42:30 +03001722 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001723
Ville Syrjäläa8f327f2015-07-09 20:14:11 +03001724 /* Assert data lane reset */
1725 chv_data_lane_soft_reset(encoder, true);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001726
Ville Syrjäläa5805162015-05-26 20:42:30 +03001727 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä580d3812014-04-09 13:29:00 +03001728}
1729
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001730static void chv_hdmi_pre_enable(struct intel_encoder *encoder,
1731 struct intel_crtc_state *pipe_config,
1732 struct drm_connector_state *conn_state)
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001733{
1734 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
Clint Taylorb4eb1562014-11-21 11:13:02 -08001735 struct intel_hdmi *intel_hdmi = &dport->hdmi;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001736 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001737 struct drm_i915_private *dev_priv = to_i915(dev);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001738
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03001739 chv_phy_pre_encoder_enable(encoder);
Ville Syrjäläa02ef3c2014-08-18 14:42:45 +03001740
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001741 /* FIXME: Program the support xxx V-dB */
1742 /* Use 800mV-0dB */
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03001743 chv_set_phy_signal_level(encoder, 128, 102, false);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001744
Clint Taylorb4eb1562014-11-21 11:13:02 -08001745 intel_hdmi->set_infoframes(&encoder->base,
Maarten Lankhorstac240282016-11-23 15:57:00 +01001746 pipe_config->has_hdmi_sink,
1747 pipe_config, conn_state);
Clint Taylorb4eb1562014-11-21 11:13:02 -08001748
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02001749 g4x_enable_hdmi(encoder, pipe_config, conn_state);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001750
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001751 vlv_wait_port_ready(dev_priv, dport, 0x0);
Ville Syrjäläb0b33842015-07-08 23:45:55 +03001752
1753 /* Second common lane will stay alive on its own now */
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +03001754 chv_phy_release_cl2_override(encoder);
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001755}
1756
Eric Anholt7d573822009-01-02 13:33:00 -08001757static void intel_hdmi_destroy(struct drm_connector *connector)
1758{
Chris Wilson10e972d2014-09-04 21:43:45 +01001759 kfree(to_intel_connector(connector)->detect_edid);
Eric Anholt7d573822009-01-02 13:33:00 -08001760 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +08001761 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001762}
1763
Eric Anholt7d573822009-01-02 13:33:00 -08001764static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02001765 .dpms = drm_atomic_helper_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -08001766 .detect = intel_hdmi_detect,
Chris Wilson953ece6972014-09-02 20:04:01 +01001767 .force = intel_hdmi_force,
Eric Anholt7d573822009-01-02 13:33:00 -08001768 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001769 .set_property = intel_hdmi_set_property,
Matt Roper2545e4a2015-01-22 16:51:27 -08001770 .atomic_get_property = intel_connector_atomic_get_property,
Chris Wilson1ebaa0b2016-06-24 14:00:15 +01001771 .late_register = intel_connector_register,
Chris Wilsonc191eca2016-06-17 11:40:33 +01001772 .early_unregister = intel_connector_unregister,
Eric Anholt7d573822009-01-02 13:33:00 -08001773 .destroy = intel_hdmi_destroy,
Matt Roperc6f95f22015-01-22 16:50:32 -08001774 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Ander Conselvan de Oliveira98969722015-03-20 16:18:06 +02001775 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Eric Anholt7d573822009-01-02 13:33:00 -08001776};
1777
1778static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
1779 .get_modes = intel_hdmi_get_modes,
1780 .mode_valid = intel_hdmi_mode_valid,
Eric Anholt7d573822009-01-02 13:33:00 -08001781};
1782
Eric Anholt7d573822009-01-02 13:33:00 -08001783static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001784 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -08001785};
1786
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001787static void
1788intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
1789{
Chris Wilson3f43c482011-05-12 22:17:24 +01001790 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00001791 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001792 intel_hdmi->color_range_auto = true;
Vandana Kannan94a11dd2014-06-11 11:06:01 +05301793 intel_attach_aspect_ratio_property(connector);
1794 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001795}
1796
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001797static u8 intel_hdmi_ddc_pin(struct drm_i915_private *dev_priv,
1798 enum port port)
1799{
1800 const struct ddi_vbt_port_info *info =
1801 &dev_priv->vbt.ddi_port_info[port];
1802 u8 ddc_pin;
1803
1804 if (info->alternate_ddc_pin) {
1805 DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (VBT)\n",
1806 info->alternate_ddc_pin, port_name(port));
1807 return info->alternate_ddc_pin;
1808 }
1809
1810 switch (port) {
1811 case PORT_B:
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001812 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001813 ddc_pin = GMBUS_PIN_1_BXT;
1814 else
1815 ddc_pin = GMBUS_PIN_DPB;
1816 break;
1817 case PORT_C:
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001818 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001819 ddc_pin = GMBUS_PIN_2_BXT;
1820 else
1821 ddc_pin = GMBUS_PIN_DPC;
1822 break;
1823 case PORT_D:
1824 if (IS_CHERRYVIEW(dev_priv))
1825 ddc_pin = GMBUS_PIN_DPD_CHV;
1826 else
1827 ddc_pin = GMBUS_PIN_DPD;
1828 break;
1829 default:
1830 MISSING_CASE(port);
1831 ddc_pin = GMBUS_PIN_DPB;
1832 break;
1833 }
1834
1835 DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (platform default)\n",
1836 ddc_pin, port_name(port));
1837
1838 return ddc_pin;
1839}
1840
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001841void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1842 struct intel_connector *intel_connector)
Eric Anholt7d573822009-01-02 13:33:00 -08001843{
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001844 struct drm_connector *connector = &intel_connector->base;
1845 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
1846 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1847 struct drm_device *dev = intel_encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001848 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni174edf12012-10-26 19:05:50 -02001849 enum port port = intel_dig_port->port;
Eric Anholt7d573822009-01-02 13:33:00 -08001850
Ville Syrjälä22f350422016-06-03 12:17:43 +03001851 DRM_DEBUG_KMS("Adding HDMI connector on port %c\n",
1852 port_name(port));
1853
Ville Syrjäläccb1a832015-12-08 19:59:38 +02001854 if (WARN(intel_dig_port->max_lanes < 4,
1855 "Not enough lanes (%d) for HDMI on port %c\n",
1856 intel_dig_port->max_lanes, port_name(port)))
1857 return;
1858
Eric Anholt7d573822009-01-02 13:33:00 -08001859 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -04001860 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -08001861 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
1862
Peter Rossc3febcc2012-01-28 14:49:26 +01001863 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001864 connector->doublescan_allowed = 0;
Damien Lespiau573e74a2013-09-25 16:45:40 +01001865 connector->stereo_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001866
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001867 intel_hdmi->ddc_bus = intel_hdmi_ddc_pin(dev_priv, port);
1868
Daniel Vetter08d644a2012-07-12 20:19:59 +02001869 switch (port) {
1870 case PORT_B:
Ander Conselvan de Oliveiraca4c3892017-02-03 16:03:13 +02001871 intel_encoder->hpd_pin = HPD_PORT_B;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001872 break;
1873 case PORT_C:
Egbert Eich1d843f92013-02-25 12:06:49 -05001874 intel_encoder->hpd_pin = HPD_PORT_C;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001875 break;
1876 case PORT_D:
Egbert Eich1d843f92013-02-25 12:06:49 -05001877 intel_encoder->hpd_pin = HPD_PORT_D;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001878 break;
Xiong Zhang11c1b652015-08-17 16:04:04 +08001879 case PORT_E:
Xiong Zhang11c1b652015-08-17 16:04:04 +08001880 intel_encoder->hpd_pin = HPD_PORT_E;
1881 break;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001882 default:
Ville Syrjäläe4ab73a2016-10-11 20:52:46 +03001883 MISSING_CASE(port);
1884 return;
Ma Lingf8aed702009-08-24 13:50:24 +08001885 }
Eric Anholt7d573822009-01-02 13:33:00 -08001886
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001887 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Shobhit Kumar90b107c2012-03-28 13:39:32 -07001888 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001889 intel_hdmi->set_infoframes = vlv_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001890 intel_hdmi->infoframe_enabled = vlv_infoframe_enabled;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001891 } else if (IS_G4X(dev_priv)) {
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001892 intel_hdmi->write_infoframe = g4x_write_infoframe;
1893 intel_hdmi->set_infoframes = g4x_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001894 intel_hdmi->infoframe_enabled = g4x_infoframe_enabled;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001895 } else if (HAS_DDI(dev_priv)) {
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -03001896 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001897 intel_hdmi->set_infoframes = hsw_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001898 intel_hdmi->infoframe_enabled = hsw_infoframe_enabled;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001899 } else if (HAS_PCH_IBX(dev_priv)) {
Paulo Zanonifdf12502012-05-04 17:18:24 -03001900 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001901 intel_hdmi->set_infoframes = ibx_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001902 intel_hdmi->infoframe_enabled = ibx_infoframe_enabled;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001903 } else {
1904 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001905 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnese43823e2014-11-05 14:26:08 -08001906 intel_hdmi->infoframe_enabled = cpt_infoframe_enabled;
Jesse Barnes64a8fc02011-09-22 11:16:00 +05301907 }
Jesse Barnes45187ac2011-08-03 09:22:55 -07001908
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001909 if (HAS_DDI(dev_priv))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001910 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
1911 else
1912 intel_connector->get_hw_state = intel_connector_get_hw_state;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001913
1914 intel_hdmi_add_properties(intel_hdmi, connector);
1915
1916 intel_connector_attach_encoder(intel_connector, intel_encoder);
Shashank Sharmad8b4c432015-09-04 18:56:11 +05301917 intel_hdmi->attached_connector = intel_connector;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001918
1919 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1920 * 0xd. Failure to do so will result in spurious interrupts being
1921 * generated on the port when a cable is not attached.
1922 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001923 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001924 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1925 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1926 }
1927}
1928
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02001929void intel_hdmi_init(struct drm_i915_private *dev_priv,
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001930 i915_reg_t hdmi_reg, enum port port)
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001931{
1932 struct intel_digital_port *intel_dig_port;
1933 struct intel_encoder *intel_encoder;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001934 struct intel_connector *intel_connector;
1935
Daniel Vetterb14c5672013-09-19 12:18:32 +02001936 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001937 if (!intel_dig_port)
1938 return;
1939
Ander Conselvan de Oliveira08d9bc92015-04-10 10:59:10 +03001940 intel_connector = intel_connector_alloc();
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001941 if (!intel_connector) {
1942 kfree(intel_dig_port);
1943 return;
1944 }
1945
1946 intel_encoder = &intel_dig_port->base;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001947
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02001948 drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
1949 &intel_hdmi_enc_funcs, DRM_MODE_ENCODER_TMDS,
1950 "HDMI %c", port_name(port));
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001951
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001952 intel_encoder->compute_config = intel_hdmi_compute_config;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001953 if (HAS_PCH_SPLIT(dev_priv)) {
Ville Syrjäläa4790ce2015-05-05 17:17:35 +03001954 intel_encoder->disable = pch_disable_hdmi;
1955 intel_encoder->post_disable = pch_post_disable_hdmi;
1956 } else {
1957 intel_encoder->disable = g4x_disable_hdmi;
1958 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001959 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001960 intel_encoder->get_config = intel_hdmi_get_config;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001961 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä9197c882014-04-09 13:29:05 +03001962 intel_encoder->pre_pll_enable = chv_hdmi_pre_pll_enable;
Chon Ming Leee4a1d842014-04-09 13:28:20 +03001963 intel_encoder->pre_enable = chv_hdmi_pre_enable;
1964 intel_encoder->enable = vlv_enable_hdmi;
Ville Syrjälä580d3812014-04-09 13:29:00 +03001965 intel_encoder->post_disable = chv_hdmi_post_disable;
Ville Syrjäläd6db9952015-07-08 23:45:49 +03001966 intel_encoder->post_pll_disable = chv_hdmi_post_pll_disable;
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01001967 } else if (IS_VALLEYVIEW(dev_priv)) {
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001968 intel_encoder->pre_pll_enable = vlv_hdmi_pre_pll_enable;
1969 intel_encoder->pre_enable = vlv_hdmi_pre_enable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001970 intel_encoder->enable = vlv_enable_hdmi;
Chon Ming Lee9514ac62013-10-16 17:07:41 +08001971 intel_encoder->post_disable = vlv_hdmi_post_disable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001972 } else {
Jesse Barnes13732ba2014-04-05 11:51:35 -07001973 intel_encoder->pre_enable = intel_hdmi_pre_enable;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001974 if (HAS_PCH_CPT(dev_priv))
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001975 intel_encoder->enable = cpt_enable_hdmi;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001976 else if (HAS_PCH_IBX(dev_priv))
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001977 intel_encoder->enable = ibx_enable_hdmi;
Ville Syrjäläd1b15892015-05-05 17:06:19 +03001978 else
Ville Syrjäläbf868c72015-05-05 17:06:23 +03001979 intel_encoder->enable = g4x_enable_hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001980 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001981
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001982 intel_encoder->type = INTEL_OUTPUT_HDMI;
Pandiyan, Dhinakaran03cdc1d2016-09-19 18:24:38 -07001983 intel_encoder->port = port;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01001984 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä882ec382014-04-28 14:07:43 +03001985 if (port == PORT_D)
1986 intel_encoder->crtc_mask = 1 << 2;
1987 else
1988 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
1989 } else {
1990 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
1991 }
Ville Syrjälä301ea742014-03-03 16:15:30 +02001992 intel_encoder->cloneable = 1 << INTEL_OUTPUT_ANALOG;
Ville Syrjäläc6f14952014-03-03 16:15:31 +02001993 /*
1994 * BSpec is unclear about HDMI+HDMI cloning on g4x, but it seems
1995 * to work on real hardware. And since g4x can send infoframes to
1996 * only one port anyway, nothing is lost by allowing it.
1997 */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01001998 if (IS_G4X(dev_priv))
Ville Syrjäläc6f14952014-03-03 16:15:31 +02001999 intel_encoder->cloneable |= 1 << INTEL_OUTPUT_HDMI;
Eric Anholt7d573822009-01-02 13:33:00 -08002000
Paulo Zanoni174edf12012-10-26 19:05:50 -02002001 intel_dig_port->port = port;
Paulo Zanonib242b7f2013-02-18 19:00:26 -03002002 intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02002003 intel_dig_port->dp.output_reg = INVALID_MMIO_REG;
Ville Syrjäläccb1a832015-12-08 19:59:38 +02002004 intel_dig_port->max_lanes = 4;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01002005
Paulo Zanonib9cb2342012-10-26 19:05:47 -02002006 intel_hdmi_init_connector(intel_dig_port, intel_connector);
Eric Anholt7d573822009-01-02 13:33:00 -08002007}