blob: dd4fa35e0a852a1ba2f6d18fe070bcbd14bf2bcc [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>
34#include <drm/drm_crtc.h>
35#include <drm/drm_edid.h>
Eric Anholt7d573822009-01-02 13:33:00 -080036#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/i915_drm.h>
Eric Anholt7d573822009-01-02 13:33:00 -080038#include "i915_drv.h"
39
Paulo Zanoni30add222012-10-26 19:05:45 -020040static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
41{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020042 return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
Paulo Zanoni30add222012-10-26 19:05:45 -020043}
44
Daniel Vetterafba0182012-06-12 16:36:45 +020045static void
46assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
47{
Paulo Zanoni30add222012-10-26 19:05:45 -020048 struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
Daniel Vetterafba0182012-06-12 16:36:45 +020049 struct drm_i915_private *dev_priv = dev->dev_private;
50 uint32_t enabled_bits;
51
Paulo Zanoniaffa9352012-11-23 15:30:39 -020052 enabled_bits = HAS_DDI(dev) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
Daniel Vetterafba0182012-06-12 16:36:45 +020053
Paulo Zanonib242b7f2013-02-18 19:00:26 -030054 WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits,
Daniel Vetterafba0182012-06-12 16:36:45 +020055 "HDMI port enabled, expecting disabled\n");
56}
57
Eugeni Dodonovf5bbfca2012-05-09 15:37:30 -030058struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
Chris Wilsonea5b2132010-08-04 13:50:23 +010059{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020060 struct intel_digital_port *intel_dig_port =
61 container_of(encoder, struct intel_digital_port, base.base);
62 return &intel_dig_port->hdmi;
Chris Wilsonea5b2132010-08-04 13:50:23 +010063}
64
Chris Wilsondf0e9242010-09-09 16:20:55 +010065static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
66{
Paulo Zanonida63a9f2012-10-26 19:05:46 -020067 return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
Chris Wilsondf0e9242010-09-09 16:20:55 +010068}
69
Damien Lespiau178f7362013-08-06 20:32:18 +010070static u32 g4x_infoframe_index(enum hdmi_infoframe_type type)
David Härdeman3c17fe42010-09-24 21:44:32 +020071{
Damien Lespiau178f7362013-08-06 20:32:18 +010072 switch (type) {
73 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030074 return VIDEO_DIP_SELECT_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010075 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030076 return VIDEO_DIP_SELECT_SPD;
Jesse Barnes45187ac2011-08-03 09:22:55 -070077 default:
Damien Lespiau178f7362013-08-06 20:32:18 +010078 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030079 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070080 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070081}
82
Damien Lespiau178f7362013-08-06 20:32:18 +010083static u32 g4x_infoframe_enable(enum hdmi_infoframe_type type)
Jesse Barnes45187ac2011-08-03 09:22:55 -070084{
Damien Lespiau178f7362013-08-06 20:32:18 +010085 switch (type) {
86 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030087 return VIDEO_DIP_ENABLE_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010088 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030089 return VIDEO_DIP_ENABLE_SPD;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030090 default:
Damien Lespiau178f7362013-08-06 20:32:18 +010091 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030092 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -030093 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -030094}
95
Damien Lespiau178f7362013-08-06 20:32:18 +010096static u32 hsw_infoframe_enable(enum hdmi_infoframe_type type)
Paulo Zanoni2da8af52012-05-14 17:12:51 -030097{
Damien Lespiau178f7362013-08-06 20:32:18 +010098 switch (type) {
99 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300100 return VIDEO_DIP_ENABLE_AVI_HSW;
Damien Lespiau178f7362013-08-06 20:32:18 +0100101 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300102 return VIDEO_DIP_ENABLE_SPD_HSW;
103 default:
Damien Lespiau178f7362013-08-06 20:32:18 +0100104 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300105 return 0;
106 }
107}
108
Damien Lespiau178f7362013-08-06 20:32:18 +0100109static u32 hsw_infoframe_data_reg(enum hdmi_infoframe_type type,
Rodrigo Vivi7d9bceb2013-02-25 19:55:16 -0300110 enum transcoder cpu_transcoder)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300111{
Damien Lespiau178f7362013-08-06 20:32:18 +0100112 switch (type) {
113 case HDMI_INFOFRAME_TYPE_AVI:
Rodrigo Vivi7d9bceb2013-02-25 19:55:16 -0300114 return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder);
Damien Lespiau178f7362013-08-06 20:32:18 +0100115 case HDMI_INFOFRAME_TYPE_SPD:
Rodrigo Vivi7d9bceb2013-02-25 19:55:16 -0300116 return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300117 default:
Damien Lespiau178f7362013-08-06 20:32:18 +0100118 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300119 return 0;
120 }
121}
122
Daniel Vettera3da1df2012-05-08 15:19:06 +0200123static void g4x_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100124 enum hdmi_infoframe_type type,
125 const uint8_t *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700126{
127 uint32_t *data = (uint32_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200128 struct drm_device *dev = encoder->dev;
129 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300130 u32 val = I915_READ(VIDEO_DIP_CTL);
Damien Lespiau178f7362013-08-06 20:32:18 +0100131 int i;
David Härdeman3c17fe42010-09-24 21:44:32 +0200132
Paulo Zanoni822974a2012-05-28 16:42:51 -0300133 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
134
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300135 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100136 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700137
Damien Lespiau178f7362013-08-06 20:32:18 +0100138 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300139
140 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700141
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300142 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700143 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200144 I915_WRITE(VIDEO_DIP_DATA, *data);
145 data++;
146 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300147 /* Write every possible data byte to force correct ECC calculation. */
148 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
149 I915_WRITE(VIDEO_DIP_DATA, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300150 mmiowb();
David Härdeman3c17fe42010-09-24 21:44:32 +0200151
Damien Lespiau178f7362013-08-06 20:32:18 +0100152 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300153 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200154 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700155
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300156 I915_WRITE(VIDEO_DIP_CTL, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300157 POSTING_READ(VIDEO_DIP_CTL);
David Härdeman3c17fe42010-09-24 21:44:32 +0200158}
159
Paulo Zanonifdf12502012-05-04 17:18:24 -0300160static void ibx_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100161 enum hdmi_infoframe_type type,
162 const uint8_t *frame, ssize_t len)
Paulo Zanonifdf12502012-05-04 17:18:24 -0300163{
164 uint32_t *data = (uint32_t *)frame;
165 struct drm_device *dev = encoder->dev;
166 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300167 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100168 int i, reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300169 u32 val = I915_READ(reg);
170
Paulo Zanoni822974a2012-05-28 16:42:51 -0300171 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
172
Paulo Zanonifdf12502012-05-04 17:18:24 -0300173 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100174 val |= g4x_infoframe_index(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300175
Damien Lespiau178f7362013-08-06 20:32:18 +0100176 val &= ~g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300177
178 I915_WRITE(reg, val);
179
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300180 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300181 for (i = 0; i < len; i += 4) {
182 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
183 data++;
184 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300185 /* Write every possible data byte to force correct ECC calculation. */
186 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
187 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300188 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300189
Damien Lespiau178f7362013-08-06 20:32:18 +0100190 val |= g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300191 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200192 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300193
194 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300195 POSTING_READ(reg);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300196}
197
198static void cpt_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100199 enum hdmi_infoframe_type type,
200 const uint8_t *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700201{
202 uint32_t *data = (uint32_t *)frame;
203 struct drm_device *dev = encoder->dev;
204 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300205 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100206 int i, reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300207 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700208
Paulo Zanoni822974a2012-05-28 16:42:51 -0300209 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
210
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530211 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100212 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700213
Paulo Zanoniecb97852012-05-04 17:18:21 -0300214 /* The DIP control register spec says that we need to update the AVI
215 * infoframe without clearing its enable bit */
Damien Lespiau178f7362013-08-06 20:32:18 +0100216 if (type != HDMI_INFOFRAME_TYPE_AVI)
217 val &= ~g4x_infoframe_enable(type);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300218
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300219 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700220
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300221 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700222 for (i = 0; i < len; i += 4) {
223 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
224 data++;
225 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300226 /* Write every possible data byte to force correct ECC calculation. */
227 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
228 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300229 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700230
Damien Lespiau178f7362013-08-06 20:32:18 +0100231 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300232 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200233 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700234
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300235 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300236 POSTING_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700237}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700238
239static void vlv_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100240 enum hdmi_infoframe_type type,
241 const uint8_t *frame, ssize_t len)
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700242{
243 uint32_t *data = (uint32_t *)frame;
244 struct drm_device *dev = encoder->dev;
245 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300246 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100247 int i, reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300248 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700249
Paulo Zanoni822974a2012-05-28 16:42:51 -0300250 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
251
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700252 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100253 val |= g4x_infoframe_index(type);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700254
Damien Lespiau178f7362013-08-06 20:32:18 +0100255 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300256
257 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700258
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300259 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700260 for (i = 0; i < len; i += 4) {
261 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
262 data++;
263 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300264 /* Write every possible data byte to force correct ECC calculation. */
265 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
266 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300267 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700268
Damien Lespiau178f7362013-08-06 20:32:18 +0100269 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300270 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200271 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700272
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300273 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300274 POSTING_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700275}
276
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300277static void hsw_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100278 enum hdmi_infoframe_type type,
279 const uint8_t *frame, ssize_t len)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300280{
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300281 uint32_t *data = (uint32_t *)frame;
282 struct drm_device *dev = encoder->dev;
283 struct drm_i915_private *dev_priv = dev->dev_private;
284 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200285 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config.cpu_transcoder);
Damien Lespiau178f7362013-08-06 20:32:18 +0100286 u32 data_reg;
287 int i;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300288 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300289
Damien Lespiau178f7362013-08-06 20:32:18 +0100290 data_reg = hsw_infoframe_data_reg(type,
291 intel_crtc->config.cpu_transcoder);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300292 if (data_reg == 0)
293 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300294
Damien Lespiau178f7362013-08-06 20:32:18 +0100295 val &= ~hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300296 I915_WRITE(ctl_reg, val);
297
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300298 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300299 for (i = 0; i < len; i += 4) {
300 I915_WRITE(data_reg + i, *data);
301 data++;
302 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300303 /* Write every possible data byte to force correct ECC calculation. */
304 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
305 I915_WRITE(data_reg + i, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300306 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300307
Damien Lespiau178f7362013-08-06 20:32:18 +0100308 val |= hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300309 I915_WRITE(ctl_reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300310 POSTING_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300311}
312
Damien Lespiau5adaea72013-08-06 20:32:19 +0100313/*
314 * The data we write to the DIP data buffer registers is 1 byte bigger than the
315 * HDMI infoframe size because of an ECC/reserved byte at position 3 (starting
316 * at 0). It's also a byte used by DisplayPort so the same DIP registers can be
317 * used for both technologies.
318 *
319 * DW0: Reserved/ECC/DP | HB2 | HB1 | HB0
320 * DW1: DB3 | DB2 | DB1 | DB0
321 * DW2: DB7 | DB6 | DB5 | DB4
322 * DW3: ...
323 *
324 * (HB is Header Byte, DB is Data Byte)
325 *
326 * The hdmi pack() functions don't know about that hardware specific hole so we
327 * trick them by giving an offset into the buffer and moving back the header
328 * bytes by one.
329 */
Damien Lespiau9198ee52013-08-06 20:32:24 +0100330static void intel_write_infoframe(struct drm_encoder *encoder,
331 union hdmi_infoframe *frame)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700332{
333 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Damien Lespiau5adaea72013-08-06 20:32:19 +0100334 uint8_t buffer[VIDEO_DIP_DATA_SIZE];
335 ssize_t len;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700336
Damien Lespiau5adaea72013-08-06 20:32:19 +0100337 /* see comment above for the reason for this offset */
338 len = hdmi_infoframe_pack(frame, buffer + 1, sizeof(buffer) - 1);
339 if (len < 0)
340 return;
341
342 /* Insert the 'hole' (see big comment above) at position 3 */
343 buffer[0] = buffer[1];
344 buffer[1] = buffer[2];
345 buffer[2] = buffer[3];
346 buffer[3] = 0;
347 len++;
348
349 intel_hdmi->write_infoframe(encoder, frame->any.type, buffer, len);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700350}
351
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300352static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Paulo Zanonic846b612012-04-13 16:31:41 -0300353 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700354{
Ville Syrjäläabedc072013-01-17 16:31:31 +0200355 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Daniel Vetter50f3b012013-03-27 00:44:56 +0100356 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau5adaea72013-08-06 20:32:19 +0100357 union hdmi_infoframe frame;
358 int ret;
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700359
Damien Lespiau5adaea72013-08-06 20:32:19 +0100360 ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
361 adjusted_mode);
362 if (ret < 0) {
363 DRM_ERROR("couldn't fill AVI infoframe\n");
364 return;
365 }
Paulo Zanonic846b612012-04-13 16:31:41 -0300366
Ville Syrjäläabedc072013-01-17 16:31:31 +0200367 if (intel_hdmi->rgb_quant_range_selectable) {
Daniel Vetter50f3b012013-03-27 00:44:56 +0100368 if (intel_crtc->config.limited_color_range)
Damien Lespiau5adaea72013-08-06 20:32:19 +0100369 frame.avi.quantization_range =
370 HDMI_QUANTIZATION_RANGE_LIMITED;
Ville Syrjäläabedc072013-01-17 16:31:31 +0200371 else
Damien Lespiau5adaea72013-08-06 20:32:19 +0100372 frame.avi.quantization_range =
373 HDMI_QUANTIZATION_RANGE_FULL;
Ville Syrjäläabedc072013-01-17 16:31:31 +0200374 }
375
Damien Lespiau9198ee52013-08-06 20:32:24 +0100376 intel_write_infoframe(encoder, &frame);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700377}
378
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300379static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700380{
Damien Lespiau5adaea72013-08-06 20:32:19 +0100381 union hdmi_infoframe frame;
382 int ret;
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700383
Damien Lespiau5adaea72013-08-06 20:32:19 +0100384 ret = hdmi_spd_infoframe_init(&frame.spd, "Intel", "Integrated gfx");
385 if (ret < 0) {
386 DRM_ERROR("couldn't fill SPD infoframe\n");
387 return;
388 }
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700389
Damien Lespiau5adaea72013-08-06 20:32:19 +0100390 frame.spd.sdi = HDMI_SPD_SDI_PC;
391
Damien Lespiau9198ee52013-08-06 20:32:24 +0100392 intel_write_infoframe(encoder, &frame);
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700393}
394
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300395static void g4x_set_infoframes(struct drm_encoder *encoder,
396 struct drm_display_mode *adjusted_mode)
397{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300398 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200399 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
400 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300401 u32 reg = VIDEO_DIP_CTL;
402 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300403 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300404
Daniel Vetterafba0182012-06-12 16:36:45 +0200405 assert_hdmi_port_disabled(intel_hdmi);
406
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300407 /* If the registers were not initialized yet, they might be zeroes,
408 * which means we're selecting the AVI DIP and we're setting its
409 * frequency to once. This seems to really confuse the HW and make
410 * things stop working (the register spec says the AVI always needs to
411 * be sent every VSync). So here we avoid writing to the register more
412 * than we need and also explicitly select the AVI DIP and explicitly
413 * set its frequency to every VSync. Avoiding to write it twice seems to
414 * be enough to solve the problem, but being defensive shouldn't hurt us
415 * either. */
416 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
417
418 if (!intel_hdmi->has_hdmi_sink) {
419 if (!(val & VIDEO_DIP_ENABLE))
420 return;
421 val &= ~VIDEO_DIP_ENABLE;
422 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300423 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300424 return;
425 }
426
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200427 switch (intel_dig_port->port) {
428 case PORT_B:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300429 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300430 break;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200431 case PORT_C:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300432 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300433 break;
434 default:
Paulo Zanoni57df2ae2012-09-24 10:32:54 -0300435 BUG();
Paulo Zanonif278d972012-05-28 16:42:50 -0300436 return;
437 }
438
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300439 if (port != (val & VIDEO_DIP_PORT_MASK)) {
440 if (val & VIDEO_DIP_ENABLE) {
441 val &= ~VIDEO_DIP_ENABLE;
442 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300443 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300444 }
445 val &= ~VIDEO_DIP_PORT_MASK;
446 val |= port;
447 }
448
Paulo Zanoni822974a2012-05-28 16:42:51 -0300449 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300450 val &= ~VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanoni822974a2012-05-28 16:42:51 -0300451
Paulo Zanonif278d972012-05-28 16:42:50 -0300452 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300453 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300454
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300455 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
456 intel_hdmi_set_spd_infoframe(encoder);
457}
458
459static void ibx_set_infoframes(struct drm_encoder *encoder,
460 struct drm_display_mode *adjusted_mode)
461{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300462 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
463 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200464 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
465 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300466 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
467 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300468 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300469
Daniel Vetterafba0182012-06-12 16:36:45 +0200470 assert_hdmi_port_disabled(intel_hdmi);
471
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300472 /* See the big comment in g4x_set_infoframes() */
473 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
474
475 if (!intel_hdmi->has_hdmi_sink) {
476 if (!(val & VIDEO_DIP_ENABLE))
477 return;
478 val &= ~VIDEO_DIP_ENABLE;
479 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300480 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300481 return;
482 }
483
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200484 switch (intel_dig_port->port) {
485 case PORT_B:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300486 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300487 break;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200488 case PORT_C:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300489 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300490 break;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200491 case PORT_D:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300492 port = VIDEO_DIP_PORT_D;
Paulo Zanonif278d972012-05-28 16:42:50 -0300493 break;
494 default:
Paulo Zanoni57df2ae2012-09-24 10:32:54 -0300495 BUG();
Paulo Zanonif278d972012-05-28 16:42:50 -0300496 return;
497 }
498
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300499 if (port != (val & VIDEO_DIP_PORT_MASK)) {
500 if (val & VIDEO_DIP_ENABLE) {
501 val &= ~VIDEO_DIP_ENABLE;
502 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300503 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300504 }
505 val &= ~VIDEO_DIP_PORT_MASK;
506 val |= port;
507 }
508
Paulo Zanoni822974a2012-05-28 16:42:51 -0300509 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300510 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
511 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300512
Paulo Zanonif278d972012-05-28 16:42:50 -0300513 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300514 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300515
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300516 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
517 intel_hdmi_set_spd_infoframe(encoder);
518}
519
520static void cpt_set_infoframes(struct drm_encoder *encoder,
521 struct drm_display_mode *adjusted_mode)
522{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300523 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
524 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
525 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
526 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
527 u32 val = I915_READ(reg);
528
Daniel Vetterafba0182012-06-12 16:36:45 +0200529 assert_hdmi_port_disabled(intel_hdmi);
530
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300531 /* See the big comment in g4x_set_infoframes() */
532 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
533
534 if (!intel_hdmi->has_hdmi_sink) {
535 if (!(val & VIDEO_DIP_ENABLE))
536 return;
537 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
538 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300539 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300540 return;
541 }
542
Paulo Zanoni822974a2012-05-28 16:42:51 -0300543 /* Set both together, unset both together: see the spec. */
544 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300545 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
546 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300547
548 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300549 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300550
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300551 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
552 intel_hdmi_set_spd_infoframe(encoder);
553}
554
555static void vlv_set_infoframes(struct drm_encoder *encoder,
556 struct drm_display_mode *adjusted_mode)
557{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300558 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
559 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
560 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
561 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
562 u32 val = I915_READ(reg);
563
Daniel Vetterafba0182012-06-12 16:36:45 +0200564 assert_hdmi_port_disabled(intel_hdmi);
565
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300566 /* See the big comment in g4x_set_infoframes() */
567 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
568
569 if (!intel_hdmi->has_hdmi_sink) {
570 if (!(val & VIDEO_DIP_ENABLE))
571 return;
572 val &= ~VIDEO_DIP_ENABLE;
573 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300574 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300575 return;
576 }
577
Paulo Zanoni822974a2012-05-28 16:42:51 -0300578 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300579 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
580 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300581
582 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300583 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300584
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300585 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
586 intel_hdmi_set_spd_infoframe(encoder);
587}
588
589static void hsw_set_infoframes(struct drm_encoder *encoder,
590 struct drm_display_mode *adjusted_mode)
591{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300592 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
593 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
594 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200595 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config.cpu_transcoder);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300596 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300597
Daniel Vetterafba0182012-06-12 16:36:45 +0200598 assert_hdmi_port_disabled(intel_hdmi);
599
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300600 if (!intel_hdmi->has_hdmi_sink) {
601 I915_WRITE(reg, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300602 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300603 return;
604 }
605
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300606 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
607 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW);
608
609 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300610 POSTING_READ(reg);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300611
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300612 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
613 intel_hdmi_set_spd_infoframe(encoder);
614}
615
Daniel Vetterc59423a2013-07-21 21:37:04 +0200616static void intel_hdmi_mode_set(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800617{
Daniel Vetterc59423a2013-07-21 21:37:04 +0200618 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800619 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterc59423a2013-07-21 21:37:04 +0200620 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
621 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
622 struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300623 u32 hdmi_val;
Eric Anholt7d573822009-01-02 13:33:00 -0800624
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300625 hdmi_val = SDVO_ENCODING_HDMI;
Ville Syrjälä2af2c492013-06-25 14:16:34 +0300626 if (!HAS_PCH_SPLIT(dev))
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300627 hdmi_val |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400628 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300629 hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400630 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300631 hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800632
Daniel Vetterc59423a2013-07-21 21:37:04 +0200633 if (crtc->config.pipe_bpp > 24)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300634 hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700635 else
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300636 hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700637
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800638 /* Required on CPT */
639 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300640 hdmi_val |= HDMI_MODE_SELECT_HDMI;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800641
David Härdeman3c17fe42010-09-24 21:44:32 +0200642 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800643 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
Daniel Vetterc59423a2013-07-21 21:37:04 +0200644 pipe_name(crtc->pipe));
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300645 hdmi_val |= SDVO_AUDIO_ENABLE;
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300646 hdmi_val |= HDMI_MODE_SELECT_HDMI;
Daniel Vetterc59423a2013-07-21 21:37:04 +0200647 intel_write_eld(&encoder->base, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200648 }
Eric Anholt7d573822009-01-02 13:33:00 -0800649
Jesse Barnes75770562011-10-12 09:01:58 -0700650 if (HAS_PCH_CPT(dev))
Daniel Vetterc59423a2013-07-21 21:37:04 +0200651 hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe);
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300652 else
Daniel Vetterc59423a2013-07-21 21:37:04 +0200653 hdmi_val |= SDVO_PIPE_SEL(crtc->pipe);
Eric Anholt7d573822009-01-02 13:33:00 -0800654
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300655 I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
656 POSTING_READ(intel_hdmi->hdmi_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200657
Daniel Vetterc59423a2013-07-21 21:37:04 +0200658 intel_hdmi->set_infoframes(&encoder->base, adjusted_mode);
Eric Anholt7d573822009-01-02 13:33:00 -0800659}
660
Daniel Vetter85234cd2012-07-02 13:27:29 +0200661static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
662 enum pipe *pipe)
Eric Anholt7d573822009-01-02 13:33:00 -0800663{
Daniel Vetter85234cd2012-07-02 13:27:29 +0200664 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800665 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200666 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
667 u32 tmp;
668
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300669 tmp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200670
671 if (!(tmp & SDVO_ENABLE))
672 return false;
673
674 if (HAS_PCH_CPT(dev))
675 *pipe = PORT_TO_PIPE_CPT(tmp);
676 else
677 *pipe = PORT_TO_PIPE(tmp);
678
679 return true;
680}
681
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700682static void intel_hdmi_get_config(struct intel_encoder *encoder,
683 struct intel_crtc_config *pipe_config)
684{
685 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
686 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
687 u32 tmp, flags = 0;
688
689 tmp = I915_READ(intel_hdmi->hdmi_reg);
690
691 if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
692 flags |= DRM_MODE_FLAG_PHSYNC;
693 else
694 flags |= DRM_MODE_FLAG_NHSYNC;
695
696 if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
697 flags |= DRM_MODE_FLAG_PVSYNC;
698 else
699 flags |= DRM_MODE_FLAG_NVSYNC;
700
701 pipe_config->adjusted_mode.flags |= flags;
702}
703
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200704static void intel_enable_hdmi(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800705{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200706 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800707 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300708 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200709 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Eric Anholt7d573822009-01-02 13:33:00 -0800710 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800711 u32 enable_bits = SDVO_ENABLE;
712
713 if (intel_hdmi->has_audio)
714 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800715
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300716 temp = I915_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000717
Daniel Vetter7a87c282012-06-05 11:03:39 +0200718 /* HW workaround for IBX, we need to move the port to transcoder A
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300719 * before disabling it, so restore the transcoder select bit here. */
720 if (HAS_PCH_IBX(dev))
721 enable_bits |= SDVO_PIPE_SEL(intel_crtc->pipe);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200722
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200723 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
724 * we do this anyway which shows more stable in testing.
725 */
726 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300727 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
728 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200729 }
Daniel Vetter7a87c282012-06-05 11:03:39 +0200730
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200731 temp |= enable_bits;
732
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300733 I915_WRITE(intel_hdmi->hdmi_reg, temp);
734 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200735
736 /* HW workaround, need to write this twice for issue that may result
737 * in first write getting masked.
738 */
739 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300740 I915_WRITE(intel_hdmi->hdmi_reg, temp);
741 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200742 }
Jani Nikulab76cf762013-07-30 12:20:31 +0300743}
Jesse Barnes89b667f2013-04-18 14:51:36 -0700744
Jani Nikulab76cf762013-07-30 12:20:31 +0300745static void vlv_enable_hdmi(struct intel_encoder *encoder)
746{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200747}
748
749static void intel_disable_hdmi(struct intel_encoder *encoder)
750{
751 struct drm_device *dev = encoder->base.dev;
752 struct drm_i915_private *dev_priv = dev->dev_private;
753 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
754 u32 temp;
Wang Xingchao3cce5742012-09-13 11:19:00 +0800755 u32 enable_bits = SDVO_ENABLE | SDVO_AUDIO_ENABLE;
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200756
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300757 temp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200758
759 /* HW workaround for IBX, we need to move the port to transcoder A
760 * before disabling it. */
761 if (HAS_PCH_IBX(dev)) {
762 struct drm_crtc *crtc = encoder->base.crtc;
763 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
764
765 if (temp & SDVO_PIPE_B_SELECT) {
766 temp &= ~SDVO_PIPE_B_SELECT;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300767 I915_WRITE(intel_hdmi->hdmi_reg, temp);
768 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200769
770 /* Again we need to write this twice. */
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300771 I915_WRITE(intel_hdmi->hdmi_reg, temp);
772 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200773
774 /* Transcoder selection bits only update
775 * effectively on vblank. */
776 if (crtc)
777 intel_wait_for_vblank(dev, pipe);
778 else
779 msleep(50);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200780 }
781 }
782
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000783 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
784 * we do this anyway which shows more stable in testing.
785 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800786 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300787 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
788 POSTING_READ(intel_hdmi->hdmi_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800789 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000790
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200791 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000792
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300793 I915_WRITE(intel_hdmi->hdmi_reg, temp);
794 POSTING_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000795
796 /* HW workaround, need to write this twice for issue that may result
797 * in first write getting masked.
798 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800799 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300800 I915_WRITE(intel_hdmi->hdmi_reg, temp);
801 POSTING_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000802 }
Eric Anholt7d573822009-01-02 13:33:00 -0800803}
804
Daniel Vetter7d148ef2013-07-22 18:02:39 +0200805static int hdmi_portclock_limit(struct intel_hdmi *hdmi)
806{
807 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
808
809 if (IS_G4X(dev))
810 return 165000;
811 else if (IS_HASWELL(dev))
812 return 300000;
813 else
814 return 225000;
815}
816
Eric Anholt7d573822009-01-02 13:33:00 -0800817static int intel_hdmi_mode_valid(struct drm_connector *connector,
818 struct drm_display_mode *mode)
819{
Daniel Vetter7d148ef2013-07-22 18:02:39 +0200820 if (mode->clock > hdmi_portclock_limit(intel_attached_hdmi(connector)))
Eric Anholt7d573822009-01-02 13:33:00 -0800821 return MODE_CLOCK_HIGH;
822 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200823 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800824
825 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
826 return MODE_NO_DBLESCAN;
827
828 return MODE_OK;
829}
830
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100831bool intel_hdmi_compute_config(struct intel_encoder *encoder,
832 struct intel_crtc_config *pipe_config)
Eric Anholt7d573822009-01-02 13:33:00 -0800833{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100834 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
835 struct drm_device *dev = encoder->base.dev;
836 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
Daniel Vetter325b9d02013-04-19 11:24:33 +0200837 int clock_12bpc = pipe_config->requested_mode.clock * 3 / 2;
Daniel Vetter7d148ef2013-07-22 18:02:39 +0200838 int portclock_limit = hdmi_portclock_limit(intel_hdmi);
Daniel Vettere29c22c2013-02-21 00:00:16 +0100839 int desired_bpp;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200840
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200841 if (intel_hdmi->color_range_auto) {
842 /* See CEA-861-E - 5.1 Default Encoding Parameters */
843 if (intel_hdmi->has_hdmi_sink &&
Thierry Reding18316c82012-12-20 15:41:44 +0100844 drm_match_cea_mode(adjusted_mode) > 1)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300845 intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200846 else
847 intel_hdmi->color_range = 0;
848 }
849
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200850 if (intel_hdmi->color_range)
Daniel Vetter50f3b012013-03-27 00:44:56 +0100851 pipe_config->limited_color_range = true;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200852
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100853 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev))
854 pipe_config->has_pch_encoder = true;
855
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100856 /*
857 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
858 * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
Daniel Vetter325b9d02013-04-19 11:24:33 +0200859 * outputs. We also need to check that the higher clock still fits
860 * within limits.
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100861 */
Daniel Vetter7d148ef2013-07-22 18:02:39 +0200862 if (pipe_config->pipe_bpp > 8*3 && clock_12bpc <= portclock_limit
Daniel Vetter325b9d02013-04-19 11:24:33 +0200863 && HAS_PCH_SPLIT(dev)) {
Daniel Vettere29c22c2013-02-21 00:00:16 +0100864 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
865 desired_bpp = 12*3;
Daniel Vetter325b9d02013-04-19 11:24:33 +0200866
867 /* Need to adjust the port link by 1.5x for 12bpc. */
Daniel Vetterff9a6752013-06-01 17:16:21 +0200868 pipe_config->port_clock = clock_12bpc;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100869 } else {
Daniel Vettere29c22c2013-02-21 00:00:16 +0100870 DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
871 desired_bpp = 8*3;
872 }
873
874 if (!pipe_config->bw_constrained) {
875 DRM_DEBUG_KMS("forcing pipe bpc to %i for HDMI\n", desired_bpp);
876 pipe_config->pipe_bpp = desired_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100877 }
878
Daniel Vetter7d148ef2013-07-22 18:02:39 +0200879 if (adjusted_mode->clock > portclock_limit) {
Daniel Vetter325b9d02013-04-19 11:24:33 +0200880 DRM_DEBUG_KMS("too high HDMI clock, rejecting mode\n");
881 return false;
882 }
883
Eric Anholt7d573822009-01-02 13:33:00 -0800884 return true;
885}
886
Keith Packardaa93d632009-05-05 09:52:46 -0700887static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100888intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800889{
Damien Lespiaub0ea7d32012-12-13 16:09:00 +0000890 struct drm_device *dev = connector->dev;
Chris Wilsondf0e9242010-09-09 16:20:55 +0100891 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -0200892 struct intel_digital_port *intel_dig_port =
893 hdmi_to_dig_port(intel_hdmi);
894 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Damien Lespiaub0ea7d32012-12-13 16:09:00 +0000895 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700896 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700897 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800898
Chris Wilson164c8592013-07-20 20:27:08 +0100899 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
900 connector->base.id, drm_get_connector_name(connector));
901
Chris Wilsonea5b2132010-08-04 13:50:23 +0100902 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800903 intel_hdmi->has_audio = false;
Ville Syrjäläabedc072013-01-17 16:31:31 +0200904 intel_hdmi->rgb_quant_range_selectable = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700905 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800906 intel_gmbus_get_adapter(dev_priv,
907 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800908
Keith Packardaa93d632009-05-05 09:52:46 -0700909 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700910 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700911 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800912 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
913 intel_hdmi->has_hdmi_sink =
914 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800915 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Ville Syrjäläabedc072013-01-17 16:31:31 +0200916 intel_hdmi->rgb_quant_range_selectable =
917 drm_rgb_quant_range_selectable(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700918 }
Keith Packardaa93d632009-05-05 09:52:46 -0700919 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800920 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800921
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100922 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800923 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
924 intel_hdmi->has_audio =
925 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Paulo Zanonid63885d2012-10-26 19:05:49 -0200926 intel_encoder->type = INTEL_OUTPUT_HDMI;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100927 }
928
Keith Packardaa93d632009-05-05 09:52:46 -0700929 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800930}
931
Eric Anholt7d573822009-01-02 13:33:00 -0800932static int intel_hdmi_get_modes(struct drm_connector *connector)
933{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100934 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700935 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800936
937 /* We should parse the EDID data and find out if it's an HDMI sink so
938 * we can send audio to it.
939 */
940
Chris Wilsonf899fc62010-07-20 15:44:45 -0700941 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800942 intel_gmbus_get_adapter(dev_priv,
943 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800944}
945
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000946static bool
947intel_hdmi_detect_audio(struct drm_connector *connector)
948{
949 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
950 struct drm_i915_private *dev_priv = connector->dev->dev_private;
951 struct edid *edid;
952 bool has_audio = false;
953
954 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800955 intel_gmbus_get_adapter(dev_priv,
956 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000957 if (edid) {
958 if (edid->input & DRM_EDID_INPUT_DIGITAL)
959 has_audio = drm_detect_monitor_audio(edid);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000960 kfree(edid);
961 }
962
963 return has_audio;
964}
965
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100966static int
967intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300968 struct drm_property *property,
969 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100970{
971 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200972 struct intel_digital_port *intel_dig_port =
973 hdmi_to_dig_port(intel_hdmi);
Chris Wilsone953fd72011-02-21 22:23:52 +0000974 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100975 int ret;
976
Rob Clark662595d2012-10-11 20:36:04 -0500977 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100978 if (ret)
979 return ret;
980
Chris Wilson3f43c482011-05-12 22:17:24 +0100981 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800982 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000983 bool has_audio;
984
985 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100986 return 0;
987
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000988 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100989
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800990 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000991 has_audio = intel_hdmi_detect_audio(connector);
992 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800993 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000994
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800995 if (i == HDMI_AUDIO_OFF_DVI)
996 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100997
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000998 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100999 goto done;
1000 }
1001
Chris Wilsone953fd72011-02-21 22:23:52 +00001002 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +02001003 bool old_auto = intel_hdmi->color_range_auto;
1004 uint32_t old_range = intel_hdmi->color_range;
1005
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001006 switch (val) {
1007 case INTEL_BROADCAST_RGB_AUTO:
1008 intel_hdmi->color_range_auto = true;
1009 break;
1010 case INTEL_BROADCAST_RGB_FULL:
1011 intel_hdmi->color_range_auto = false;
1012 intel_hdmi->color_range = 0;
1013 break;
1014 case INTEL_BROADCAST_RGB_LIMITED:
1015 intel_hdmi->color_range_auto = false;
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -03001016 intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001017 break;
1018 default:
1019 return -EINVAL;
1020 }
Daniel Vetterae4edb82013-04-22 17:07:23 +02001021
1022 if (old_auto == intel_hdmi->color_range_auto &&
1023 old_range == intel_hdmi->color_range)
1024 return 0;
1025
Chris Wilsone953fd72011-02-21 22:23:52 +00001026 goto done;
1027 }
1028
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001029 return -EINVAL;
1030
1031done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00001032 if (intel_dig_port->base.base.crtc)
1033 intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001034
1035 return 0;
1036}
1037
Jesse Barnes89b667f2013-04-18 14:51:36 -07001038static void intel_hdmi_pre_enable(struct intel_encoder *encoder)
1039{
1040 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1041 struct drm_device *dev = encoder->base.dev;
1042 struct drm_i915_private *dev_priv = dev->dev_private;
1043 struct intel_crtc *intel_crtc =
1044 to_intel_crtc(encoder->base.crtc);
1045 int port = vlv_dport_to_channel(dport);
1046 int pipe = intel_crtc->pipe;
1047 u32 val;
1048
1049 if (!IS_VALLEYVIEW(dev))
1050 return;
1051
Jesse Barnes89b667f2013-04-18 14:51:36 -07001052 /* Enable clock channels for this port */
Chris Wilson0980a602013-07-26 19:57:35 +01001053 mutex_lock(&dev_priv->dpio_lock);
Jani Nikulaae992582013-05-22 15:36:19 +03001054 val = vlv_dpio_read(dev_priv, DPIO_DATA_LANE_A(port));
Jesse Barnes89b667f2013-04-18 14:51:36 -07001055 val = 0;
1056 if (pipe)
1057 val |= (1<<21);
1058 else
1059 val &= ~(1<<21);
1060 val |= 0x001000c4;
Jani Nikulaae992582013-05-22 15:36:19 +03001061 vlv_dpio_write(dev_priv, DPIO_DATA_CHANNEL(port), val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001062
1063 /* HDMI 1.0V-2dB */
Jani Nikulaae992582013-05-22 15:36:19 +03001064 vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port), 0);
1065 vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL4(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001066 0x2b245f5f);
Jani Nikulaae992582013-05-22 15:36:19 +03001067 vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL2(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001068 0x5578b83a);
Jani Nikulaae992582013-05-22 15:36:19 +03001069 vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL3(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001070 0x0c782040);
Jani Nikulaae992582013-05-22 15:36:19 +03001071 vlv_dpio_write(dev_priv, DPIO_TX3_SWING_CTL4(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001072 0x2b247878);
Jani Nikulaae992582013-05-22 15:36:19 +03001073 vlv_dpio_write(dev_priv, DPIO_PCS_STAGGER0(port), 0x00030000);
1074 vlv_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001075 0x00002000);
Jani Nikulaae992582013-05-22 15:36:19 +03001076 vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001077 DPIO_TX_OCALINIT_EN);
1078
1079 /* Program lane clock */
Jani Nikulaae992582013-05-22 15:36:19 +03001080 vlv_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF0(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001081 0x00760018);
Jani Nikulaae992582013-05-22 15:36:19 +03001082 vlv_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF8(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001083 0x00400888);
Chris Wilson0980a602013-07-26 19:57:35 +01001084 mutex_unlock(&dev_priv->dpio_lock);
Jani Nikulab76cf762013-07-30 12:20:31 +03001085
1086 intel_enable_hdmi(encoder);
1087
1088 vlv_wait_port_ready(dev_priv, port);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001089}
1090
1091static void intel_hdmi_pre_pll_enable(struct intel_encoder *encoder)
1092{
1093 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1094 struct drm_device *dev = encoder->base.dev;
1095 struct drm_i915_private *dev_priv = dev->dev_private;
1096 int port = vlv_dport_to_channel(dport);
1097
1098 if (!IS_VALLEYVIEW(dev))
1099 return;
1100
Jesse Barnes89b667f2013-04-18 14:51:36 -07001101 /* Program Tx lane resets to default */
Chris Wilson0980a602013-07-26 19:57:35 +01001102 mutex_lock(&dev_priv->dpio_lock);
Jani Nikulaae992582013-05-22 15:36:19 +03001103 vlv_dpio_write(dev_priv, DPIO_PCS_TX(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001104 DPIO_PCS_TX_LANE2_RESET |
1105 DPIO_PCS_TX_LANE1_RESET);
Jani Nikulaae992582013-05-22 15:36:19 +03001106 vlv_dpio_write(dev_priv, DPIO_PCS_CLK(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001107 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1108 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1109 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1110 DPIO_PCS_CLK_SOFT_RESET);
1111
1112 /* Fix up inter-pair skew failure */
Jani Nikulaae992582013-05-22 15:36:19 +03001113 vlv_dpio_write(dev_priv, DPIO_PCS_STAGGER1(port), 0x00750f00);
1114 vlv_dpio_write(dev_priv, DPIO_TX_CTL(port), 0x00001500);
1115 vlv_dpio_write(dev_priv, DPIO_TX_LANE(port), 0x40400000);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001116
Jani Nikulaae992582013-05-22 15:36:19 +03001117 vlv_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001118 0x00002000);
Jani Nikulaae992582013-05-22 15:36:19 +03001119 vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001120 DPIO_TX_OCALINIT_EN);
Chris Wilson0980a602013-07-26 19:57:35 +01001121 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001122}
1123
1124static void intel_hdmi_post_disable(struct intel_encoder *encoder)
1125{
1126 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1127 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1128 int port = vlv_dport_to_channel(dport);
1129
1130 /* Reset lanes to avoid HDMI flicker (VLV w/a) */
1131 mutex_lock(&dev_priv->dpio_lock);
Jani Nikulaae992582013-05-22 15:36:19 +03001132 vlv_dpio_write(dev_priv, DPIO_PCS_TX(port), 0x00000000);
1133 vlv_dpio_write(dev_priv, DPIO_PCS_CLK(port), 0x00e00060);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001134 mutex_unlock(&dev_priv->dpio_lock);
1135}
1136
Eric Anholt7d573822009-01-02 13:33:00 -08001137static void intel_hdmi_destroy(struct drm_connector *connector)
1138{
Eric Anholt7d573822009-01-02 13:33:00 -08001139 drm_sysfs_connector_remove(connector);
1140 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +08001141 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001142}
1143
Eric Anholt7d573822009-01-02 13:33:00 -08001144static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001145 .dpms = intel_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -08001146 .detect = intel_hdmi_detect,
1147 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001148 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -08001149 .destroy = intel_hdmi_destroy,
1150};
1151
1152static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
1153 .get_modes = intel_hdmi_get_modes,
1154 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01001155 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -08001156};
1157
Eric Anholt7d573822009-01-02 13:33:00 -08001158static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001159 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -08001160};
1161
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001162static void
1163intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
1164{
Chris Wilson3f43c482011-05-12 22:17:24 +01001165 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00001166 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001167 intel_hdmi->color_range_auto = true;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001168}
1169
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001170void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1171 struct intel_connector *intel_connector)
Eric Anholt7d573822009-01-02 13:33:00 -08001172{
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001173 struct drm_connector *connector = &intel_connector->base;
1174 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
1175 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1176 struct drm_device *dev = intel_encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -08001177 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001178 enum port port = intel_dig_port->port;
Eric Anholt7d573822009-01-02 13:33:00 -08001179
Eric Anholt7d573822009-01-02 13:33:00 -08001180 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -04001181 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -08001182 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
1183
Peter Rossc3febcc2012-01-28 14:49:26 +01001184 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001185 connector->doublescan_allowed = 0;
1186
Daniel Vetter08d644a2012-07-12 20:19:59 +02001187 switch (port) {
1188 case PORT_B:
Chris Wilsonf899fc62010-07-20 15:44:45 -07001189 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Egbert Eich1d843f92013-02-25 12:06:49 -05001190 intel_encoder->hpd_pin = HPD_PORT_B;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001191 break;
1192 case PORT_C:
Chris Wilsonf899fc62010-07-20 15:44:45 -07001193 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Egbert Eich1d843f92013-02-25 12:06:49 -05001194 intel_encoder->hpd_pin = HPD_PORT_C;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001195 break;
1196 case PORT_D:
Chris Wilsonf899fc62010-07-20 15:44:45 -07001197 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Egbert Eich1d843f92013-02-25 12:06:49 -05001198 intel_encoder->hpd_pin = HPD_PORT_D;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001199 break;
1200 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05001201 intel_encoder->hpd_pin = HPD_PORT_A;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001202 /* Internal port only for eDP. */
1203 default:
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -03001204 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +08001205 }
Eric Anholt7d573822009-01-02 13:33:00 -08001206
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001207 if (IS_VALLEYVIEW(dev)) {
Shobhit Kumar90b107c2012-03-28 13:39:32 -07001208 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001209 intel_hdmi->set_infoframes = vlv_set_infoframes;
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001210 } else if (!HAS_PCH_SPLIT(dev)) {
1211 intel_hdmi->write_infoframe = g4x_write_infoframe;
1212 intel_hdmi->set_infoframes = g4x_set_infoframes;
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03001213 } else if (HAS_DDI(dev)) {
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -03001214 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001215 intel_hdmi->set_infoframes = hsw_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001216 } else if (HAS_PCH_IBX(dev)) {
1217 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001218 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001219 } else {
1220 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001221 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +05301222 }
Jesse Barnes45187ac2011-08-03 09:22:55 -07001223
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001224 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001225 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
1226 else
1227 intel_connector->get_hw_state = intel_connector_get_hw_state;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001228
1229 intel_hdmi_add_properties(intel_hdmi, connector);
1230
1231 intel_connector_attach_encoder(intel_connector, intel_encoder);
1232 drm_sysfs_connector_add(connector);
1233
1234 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1235 * 0xd. Failure to do so will result in spurious interrupts being
1236 * generated on the port when a cable is not attached.
1237 */
1238 if (IS_G4X(dev) && !IS_GM45(dev)) {
1239 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1240 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1241 }
1242}
1243
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001244void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port)
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001245{
1246 struct intel_digital_port *intel_dig_port;
1247 struct intel_encoder *intel_encoder;
1248 struct drm_encoder *encoder;
1249 struct intel_connector *intel_connector;
1250
1251 intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL);
1252 if (!intel_dig_port)
1253 return;
1254
1255 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
1256 if (!intel_connector) {
1257 kfree(intel_dig_port);
1258 return;
1259 }
1260
1261 intel_encoder = &intel_dig_port->base;
1262 encoder = &intel_encoder->base;
1263
1264 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
1265 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001266
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001267 intel_encoder->compute_config = intel_hdmi_compute_config;
Daniel Vetterc59423a2013-07-21 21:37:04 +02001268 intel_encoder->mode_set = intel_hdmi_mode_set;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001269 intel_encoder->disable = intel_disable_hdmi;
1270 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001271 intel_encoder->get_config = intel_hdmi_get_config;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001272 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -07001273 intel_encoder->pre_pll_enable = intel_hdmi_pre_pll_enable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001274 intel_encoder->pre_enable = intel_hdmi_pre_enable;
1275 intel_encoder->enable = vlv_enable_hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001276 intel_encoder->post_disable = intel_hdmi_post_disable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001277 } else {
1278 intel_encoder->enable = intel_enable_hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001279 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001280
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001281 intel_encoder->type = INTEL_OUTPUT_HDMI;
1282 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
1283 intel_encoder->cloneable = false;
Eric Anholt7d573822009-01-02 13:33:00 -08001284
Paulo Zanoni174edf12012-10-26 19:05:50 -02001285 intel_dig_port->port = port;
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001286 intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001287 intel_dig_port->dp.output_reg = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001288
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001289 intel_hdmi_init_connector(intel_dig_port, intel_connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001290}