blob: 951f4817e1b650f3d6d68c1bd2d7ed42551ba268 [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
Jesse Barnes45187ac2011-08-03 09:22:55 -070070void intel_dip_infoframe_csum(struct dip_infoframe *frame)
David Härdeman3c17fe42010-09-24 21:44:32 +020071{
Jesse Barnes45187ac2011-08-03 09:22:55 -070072 uint8_t *data = (uint8_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +020073 uint8_t sum = 0;
74 unsigned i;
75
Jesse Barnes45187ac2011-08-03 09:22:55 -070076 frame->checksum = 0;
77 frame->ecc = 0;
David Härdeman3c17fe42010-09-24 21:44:32 +020078
Jesse Barnes64a8fc02011-09-22 11:16:00 +053079 for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
David Härdeman3c17fe42010-09-24 21:44:32 +020080 sum += data[i];
81
Jesse Barnes45187ac2011-08-03 09:22:55 -070082 frame->checksum = 0x100 - sum;
David Härdeman3c17fe42010-09-24 21:44:32 +020083}
84
Damien Lespiau178f7362013-08-06 20:32:18 +010085static u32 g4x_infoframe_index(enum hdmi_infoframe_type type)
David Härdeman3c17fe42010-09-24 21:44:32 +020086{
Damien Lespiau178f7362013-08-06 20:32:18 +010087 switch (type) {
88 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -030089 return VIDEO_DIP_SELECT_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +010090 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -030091 return VIDEO_DIP_SELECT_SPD;
Jesse Barnes45187ac2011-08-03 09:22:55 -070092 default:
Damien Lespiau178f7362013-08-06 20:32:18 +010093 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanonied517fb2012-05-14 17:12:50 -030094 return 0;
Jesse Barnes45187ac2011-08-03 09:22:55 -070095 }
Jesse Barnes45187ac2011-08-03 09:22:55 -070096}
97
Damien Lespiau178f7362013-08-06 20:32:18 +010098static u32 g4x_infoframe_enable(enum hdmi_infoframe_type type)
Jesse Barnes45187ac2011-08-03 09:22:55 -070099{
Damien Lespiau178f7362013-08-06 20:32:18 +0100100 switch (type) {
101 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanonied517fb2012-05-14 17:12:50 -0300102 return VIDEO_DIP_ENABLE_AVI;
Damien Lespiau178f7362013-08-06 20:32:18 +0100103 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanonied517fb2012-05-14 17:12:50 -0300104 return VIDEO_DIP_ENABLE_SPD;
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300105 default:
Damien Lespiau178f7362013-08-06 20:32:18 +0100106 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanonied517fb2012-05-14 17:12:50 -0300107 return 0;
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300108 }
Paulo Zanonifa193ff2012-05-04 17:18:20 -0300109}
110
Damien Lespiau178f7362013-08-06 20:32:18 +0100111static u32 hsw_infoframe_enable(enum hdmi_infoframe_type type)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300112{
Damien Lespiau178f7362013-08-06 20:32:18 +0100113 switch (type) {
114 case HDMI_INFOFRAME_TYPE_AVI:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300115 return VIDEO_DIP_ENABLE_AVI_HSW;
Damien Lespiau178f7362013-08-06 20:32:18 +0100116 case HDMI_INFOFRAME_TYPE_SPD:
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300117 return VIDEO_DIP_ENABLE_SPD_HSW;
118 default:
Damien Lespiau178f7362013-08-06 20:32:18 +0100119 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300120 return 0;
121 }
122}
123
Damien Lespiau178f7362013-08-06 20:32:18 +0100124static u32 hsw_infoframe_data_reg(enum hdmi_infoframe_type type,
Rodrigo Vivi7d9bceb2013-02-25 19:55:16 -0300125 enum transcoder cpu_transcoder)
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300126{
Damien Lespiau178f7362013-08-06 20:32:18 +0100127 switch (type) {
128 case HDMI_INFOFRAME_TYPE_AVI:
Rodrigo Vivi7d9bceb2013-02-25 19:55:16 -0300129 return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder);
Damien Lespiau178f7362013-08-06 20:32:18 +0100130 case HDMI_INFOFRAME_TYPE_SPD:
Rodrigo Vivi7d9bceb2013-02-25 19:55:16 -0300131 return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300132 default:
Damien Lespiau178f7362013-08-06 20:32:18 +0100133 DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300134 return 0;
135 }
136}
137
Daniel Vettera3da1df2012-05-08 15:19:06 +0200138static void g4x_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100139 enum hdmi_infoframe_type type,
140 const uint8_t *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700141{
142 uint32_t *data = (uint32_t *)frame;
David Härdeman3c17fe42010-09-24 21:44:32 +0200143 struct drm_device *dev = encoder->dev;
144 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300145 u32 val = I915_READ(VIDEO_DIP_CTL);
Damien Lespiau178f7362013-08-06 20:32:18 +0100146 int i;
David Härdeman3c17fe42010-09-24 21:44:32 +0200147
Paulo Zanoni822974a2012-05-28 16:42:51 -0300148 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
149
Paulo Zanoni1d4f85a2012-05-04 17:18:18 -0300150 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100151 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700152
Damien Lespiau178f7362013-08-06 20:32:18 +0100153 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300154
155 I915_WRITE(VIDEO_DIP_CTL, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700156
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300157 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700158 for (i = 0; i < len; i += 4) {
David Härdeman3c17fe42010-09-24 21:44:32 +0200159 I915_WRITE(VIDEO_DIP_DATA, *data);
160 data++;
161 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300162 /* Write every possible data byte to force correct ECC calculation. */
163 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
164 I915_WRITE(VIDEO_DIP_DATA, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300165 mmiowb();
David Härdeman3c17fe42010-09-24 21:44:32 +0200166
Damien Lespiau178f7362013-08-06 20:32:18 +0100167 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300168 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200169 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700170
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300171 I915_WRITE(VIDEO_DIP_CTL, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300172 POSTING_READ(VIDEO_DIP_CTL);
David Härdeman3c17fe42010-09-24 21:44:32 +0200173}
174
Paulo Zanonifdf12502012-05-04 17:18:24 -0300175static void ibx_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100176 enum hdmi_infoframe_type type,
177 const uint8_t *frame, ssize_t len)
Paulo Zanonifdf12502012-05-04 17:18:24 -0300178{
179 uint32_t *data = (uint32_t *)frame;
180 struct drm_device *dev = encoder->dev;
181 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300182 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100183 int i, reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300184 u32 val = I915_READ(reg);
185
Paulo Zanoni822974a2012-05-28 16:42:51 -0300186 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
187
Paulo Zanonifdf12502012-05-04 17:18:24 -0300188 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100189 val |= g4x_infoframe_index(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300190
Damien Lespiau178f7362013-08-06 20:32:18 +0100191 val &= ~g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300192
193 I915_WRITE(reg, val);
194
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300195 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300196 for (i = 0; i < len; i += 4) {
197 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
198 data++;
199 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300200 /* Write every possible data byte to force correct ECC calculation. */
201 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
202 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300203 mmiowb();
Paulo Zanonifdf12502012-05-04 17:18:24 -0300204
Damien Lespiau178f7362013-08-06 20:32:18 +0100205 val |= g4x_infoframe_enable(type);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300206 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200207 val |= VIDEO_DIP_FREQ_VSYNC;
Paulo Zanonifdf12502012-05-04 17:18:24 -0300208
209 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300210 POSTING_READ(reg);
Paulo Zanonifdf12502012-05-04 17:18:24 -0300211}
212
213static void cpt_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100214 enum hdmi_infoframe_type type,
215 const uint8_t *frame, ssize_t len)
Jesse Barnes45187ac2011-08-03 09:22:55 -0700216{
217 uint32_t *data = (uint32_t *)frame;
218 struct drm_device *dev = encoder->dev;
219 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300220 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100221 int i, reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300222 u32 val = I915_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700223
Paulo Zanoni822974a2012-05-28 16:42:51 -0300224 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
225
Jesse Barnes64a8fc02011-09-22 11:16:00 +0530226 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100227 val |= g4x_infoframe_index(type);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700228
Paulo Zanoniecb97852012-05-04 17:18:21 -0300229 /* The DIP control register spec says that we need to update the AVI
230 * infoframe without clearing its enable bit */
Damien Lespiau178f7362013-08-06 20:32:18 +0100231 if (type != HDMI_INFOFRAME_TYPE_AVI)
232 val &= ~g4x_infoframe_enable(type);
Paulo Zanoniecb97852012-05-04 17:18:21 -0300233
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300234 I915_WRITE(reg, val);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700235
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300236 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700237 for (i = 0; i < len; i += 4) {
238 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
239 data++;
240 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300241 /* Write every possible data byte to force correct ECC calculation. */
242 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
243 I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300244 mmiowb();
Jesse Barnes45187ac2011-08-03 09:22:55 -0700245
Damien Lespiau178f7362013-08-06 20:32:18 +0100246 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300247 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200248 val |= VIDEO_DIP_FREQ_VSYNC;
Jesse Barnes45187ac2011-08-03 09:22:55 -0700249
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300250 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300251 POSTING_READ(reg);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700252}
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700253
254static void vlv_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100255 enum hdmi_infoframe_type type,
256 const uint8_t *frame, ssize_t len)
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700257{
258 uint32_t *data = (uint32_t *)frame;
259 struct drm_device *dev = encoder->dev;
260 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonied517fb2012-05-14 17:12:50 -0300261 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Damien Lespiau178f7362013-08-06 20:32:18 +0100262 int i, reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300263 u32 val = I915_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700264
Paulo Zanoni822974a2012-05-28 16:42:51 -0300265 WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
266
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700267 val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
Damien Lespiau178f7362013-08-06 20:32:18 +0100268 val |= g4x_infoframe_index(type);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700269
Damien Lespiau178f7362013-08-06 20:32:18 +0100270 val &= ~g4x_infoframe_enable(type);
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300271
272 I915_WRITE(reg, val);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700273
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300274 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700275 for (i = 0; i < len; i += 4) {
276 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
277 data++;
278 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300279 /* Write every possible data byte to force correct ECC calculation. */
280 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
281 I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300282 mmiowb();
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700283
Damien Lespiau178f7362013-08-06 20:32:18 +0100284 val |= g4x_infoframe_enable(type);
Paulo Zanoni60c5ea22012-05-04 17:18:22 -0300285 val &= ~VIDEO_DIP_FREQ_MASK;
Daniel Vetter4b24c932012-05-08 14:41:00 +0200286 val |= VIDEO_DIP_FREQ_VSYNC;
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700287
Paulo Zanoni22509ec2012-05-04 17:18:17 -0300288 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300289 POSTING_READ(reg);
Shobhit Kumar90b107c2012-03-28 13:39:32 -0700290}
291
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300292static void hsw_write_infoframe(struct drm_encoder *encoder,
Damien Lespiau178f7362013-08-06 20:32:18 +0100293 enum hdmi_infoframe_type type,
294 const uint8_t *frame, ssize_t len)
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300295{
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300296 uint32_t *data = (uint32_t *)frame;
297 struct drm_device *dev = encoder->dev;
298 struct drm_i915_private *dev_priv = dev->dev_private;
299 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200300 u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config.cpu_transcoder);
Damien Lespiau178f7362013-08-06 20:32:18 +0100301 u32 data_reg;
302 int i;
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300303 u32 val = I915_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300304
Damien Lespiau178f7362013-08-06 20:32:18 +0100305 data_reg = hsw_infoframe_data_reg(type,
306 intel_crtc->config.cpu_transcoder);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300307 if (data_reg == 0)
308 return;
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300309
Damien Lespiau178f7362013-08-06 20:32:18 +0100310 val &= ~hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300311 I915_WRITE(ctl_reg, val);
312
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300313 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300314 for (i = 0; i < len; i += 4) {
315 I915_WRITE(data_reg + i, *data);
316 data++;
317 }
Paulo Zanoniadf00b22012-09-25 13:23:34 -0300318 /* Write every possible data byte to force correct ECC calculation. */
319 for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
320 I915_WRITE(data_reg + i, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300321 mmiowb();
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300322
Damien Lespiau178f7362013-08-06 20:32:18 +0100323 val |= hsw_infoframe_enable(type);
Paulo Zanoni2da8af52012-05-14 17:12:51 -0300324 I915_WRITE(ctl_reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300325 POSTING_READ(ctl_reg);
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -0300326}
327
Jesse Barnes45187ac2011-08-03 09:22:55 -0700328static void intel_set_infoframe(struct drm_encoder *encoder,
329 struct dip_infoframe *frame)
330{
331 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
332
Jesse Barnes45187ac2011-08-03 09:22:55 -0700333 intel_dip_infoframe_csum(frame);
Damien Lespiau178f7362013-08-06 20:32:18 +0100334 intel_hdmi->write_infoframe(encoder, frame->type, (uint8_t *)frame,
335 DIP_HEADER_SIZE + frame->len);
Jesse Barnes45187ac2011-08-03 09:22:55 -0700336}
337
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300338static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
Paulo Zanonic846b612012-04-13 16:31:41 -0300339 struct drm_display_mode *adjusted_mode)
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700340{
Ville Syrjäläabedc072013-01-17 16:31:31 +0200341 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Daniel Vetter50f3b012013-03-27 00:44:56 +0100342 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700343 struct dip_infoframe avi_if = {
344 .type = DIP_TYPE_AVI,
345 .ver = DIP_VERSION_AVI,
346 .len = DIP_LEN_AVI,
347 };
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700348
Paulo Zanonic846b612012-04-13 16:31:41 -0300349 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
350 avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
351
Ville Syrjäläabedc072013-01-17 16:31:31 +0200352 if (intel_hdmi->rgb_quant_range_selectable) {
Daniel Vetter50f3b012013-03-27 00:44:56 +0100353 if (intel_crtc->config.limited_color_range)
Ville Syrjäläabedc072013-01-17 16:31:31 +0200354 avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_LIMITED;
355 else
356 avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_FULL;
357 }
358
Thierry Reding18316c82012-12-20 15:41:44 +0100359 avi_if.body.avi.VIC = drm_match_cea_mode(adjusted_mode);
Paulo Zanoni9a69b882012-11-23 12:09:27 -0200360
Jesse Barnes45187ac2011-08-03 09:22:55 -0700361 intel_set_infoframe(encoder, &avi_if);
Jesse Barnesb055c8f2011-07-08 11:31:57 -0700362}
363
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300364static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
Jesse Barnesc0864cb2011-08-03 09:22:56 -0700365{
366 struct dip_infoframe spd_if;
367
368 memset(&spd_if, 0, sizeof(spd_if));
369 spd_if.type = DIP_TYPE_SPD;
370 spd_if.ver = DIP_VERSION_SPD;
371 spd_if.len = DIP_LEN_SPD;
372 strcpy(spd_if.body.spd.vn, "Intel");
373 strcpy(spd_if.body.spd.pd, "Integrated gfx");
374 spd_if.body.spd.sdi = DIP_SPD_PC;
375
376 intel_set_infoframe(encoder, &spd_if);
377}
378
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300379static void g4x_set_infoframes(struct drm_encoder *encoder,
380 struct drm_display_mode *adjusted_mode)
381{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300382 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200383 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
384 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300385 u32 reg = VIDEO_DIP_CTL;
386 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300387 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300388
Daniel Vetterafba0182012-06-12 16:36:45 +0200389 assert_hdmi_port_disabled(intel_hdmi);
390
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300391 /* If the registers were not initialized yet, they might be zeroes,
392 * which means we're selecting the AVI DIP and we're setting its
393 * frequency to once. This seems to really confuse the HW and make
394 * things stop working (the register spec says the AVI always needs to
395 * be sent every VSync). So here we avoid writing to the register more
396 * than we need and also explicitly select the AVI DIP and explicitly
397 * set its frequency to every VSync. Avoiding to write it twice seems to
398 * be enough to solve the problem, but being defensive shouldn't hurt us
399 * either. */
400 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
401
402 if (!intel_hdmi->has_hdmi_sink) {
403 if (!(val & VIDEO_DIP_ENABLE))
404 return;
405 val &= ~VIDEO_DIP_ENABLE;
406 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300407 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300408 return;
409 }
410
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200411 switch (intel_dig_port->port) {
412 case PORT_B:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300413 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300414 break;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200415 case PORT_C:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300416 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300417 break;
418 default:
Paulo Zanoni57df2ae2012-09-24 10:32:54 -0300419 BUG();
Paulo Zanonif278d972012-05-28 16:42:50 -0300420 return;
421 }
422
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300423 if (port != (val & VIDEO_DIP_PORT_MASK)) {
424 if (val & VIDEO_DIP_ENABLE) {
425 val &= ~VIDEO_DIP_ENABLE;
426 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300427 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300428 }
429 val &= ~VIDEO_DIP_PORT_MASK;
430 val |= port;
431 }
432
Paulo Zanoni822974a2012-05-28 16:42:51 -0300433 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300434 val &= ~VIDEO_DIP_ENABLE_VENDOR;
Paulo Zanoni822974a2012-05-28 16:42:51 -0300435
Paulo Zanonif278d972012-05-28 16:42:50 -0300436 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300437 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300438
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300439 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
440 intel_hdmi_set_spd_infoframe(encoder);
441}
442
443static void ibx_set_infoframes(struct drm_encoder *encoder,
444 struct drm_display_mode *adjusted_mode)
445{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300446 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
447 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200448 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
449 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300450 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
451 u32 val = I915_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300452 u32 port;
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300453
Daniel Vetterafba0182012-06-12 16:36:45 +0200454 assert_hdmi_port_disabled(intel_hdmi);
455
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300456 /* See the big comment in g4x_set_infoframes() */
457 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
458
459 if (!intel_hdmi->has_hdmi_sink) {
460 if (!(val & VIDEO_DIP_ENABLE))
461 return;
462 val &= ~VIDEO_DIP_ENABLE;
463 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300464 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300465 return;
466 }
467
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200468 switch (intel_dig_port->port) {
469 case PORT_B:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300470 port = VIDEO_DIP_PORT_B;
Paulo Zanonif278d972012-05-28 16:42:50 -0300471 break;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200472 case PORT_C:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300473 port = VIDEO_DIP_PORT_C;
Paulo Zanonif278d972012-05-28 16:42:50 -0300474 break;
Ville Syrjälä69fde0a2013-01-24 15:29:26 +0200475 case PORT_D:
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300476 port = VIDEO_DIP_PORT_D;
Paulo Zanonif278d972012-05-28 16:42:50 -0300477 break;
478 default:
Paulo Zanoni57df2ae2012-09-24 10:32:54 -0300479 BUG();
Paulo Zanonif278d972012-05-28 16:42:50 -0300480 return;
481 }
482
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300483 if (port != (val & VIDEO_DIP_PORT_MASK)) {
484 if (val & VIDEO_DIP_ENABLE) {
485 val &= ~VIDEO_DIP_ENABLE;
486 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300487 POSTING_READ(reg);
Paulo Zanoni72b78c92012-05-28 16:42:54 -0300488 }
489 val &= ~VIDEO_DIP_PORT_MASK;
490 val |= port;
491 }
492
Paulo Zanoni822974a2012-05-28 16:42:51 -0300493 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300494 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
495 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300496
Paulo Zanonif278d972012-05-28 16:42:50 -0300497 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300498 POSTING_READ(reg);
Paulo Zanonif278d972012-05-28 16:42:50 -0300499
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300500 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
501 intel_hdmi_set_spd_infoframe(encoder);
502}
503
504static void cpt_set_infoframes(struct drm_encoder *encoder,
505 struct drm_display_mode *adjusted_mode)
506{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300507 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
508 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
509 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
510 u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
511 u32 val = I915_READ(reg);
512
Daniel Vetterafba0182012-06-12 16:36:45 +0200513 assert_hdmi_port_disabled(intel_hdmi);
514
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300515 /* See the big comment in g4x_set_infoframes() */
516 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
517
518 if (!intel_hdmi->has_hdmi_sink) {
519 if (!(val & VIDEO_DIP_ENABLE))
520 return;
521 val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
522 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300523 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300524 return;
525 }
526
Paulo Zanoni822974a2012-05-28 16:42:51 -0300527 /* Set both together, unset both together: see the spec. */
528 val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300529 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
530 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300531
532 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300533 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300534
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300535 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
536 intel_hdmi_set_spd_infoframe(encoder);
537}
538
539static void vlv_set_infoframes(struct drm_encoder *encoder,
540 struct drm_display_mode *adjusted_mode)
541{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300542 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
543 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
544 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
545 u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
546 u32 val = I915_READ(reg);
547
Daniel Vetterafba0182012-06-12 16:36:45 +0200548 assert_hdmi_port_disabled(intel_hdmi);
549
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300550 /* See the big comment in g4x_set_infoframes() */
551 val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
552
553 if (!intel_hdmi->has_hdmi_sink) {
554 if (!(val & VIDEO_DIP_ENABLE))
555 return;
556 val &= ~VIDEO_DIP_ENABLE;
557 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300558 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300559 return;
560 }
561
Paulo Zanoni822974a2012-05-28 16:42:51 -0300562 val |= VIDEO_DIP_ENABLE;
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300563 val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
564 VIDEO_DIP_ENABLE_GCP);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300565
566 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300567 POSTING_READ(reg);
Paulo Zanoni822974a2012-05-28 16:42:51 -0300568
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300569 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
570 intel_hdmi_set_spd_infoframe(encoder);
571}
572
573static void hsw_set_infoframes(struct drm_encoder *encoder,
574 struct drm_display_mode *adjusted_mode)
575{
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300576 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
577 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
578 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
Daniel Vetter3b117c82013-04-17 20:15:07 +0200579 u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config.cpu_transcoder);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300580 u32 val = I915_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300581
Daniel Vetterafba0182012-06-12 16:36:45 +0200582 assert_hdmi_port_disabled(intel_hdmi);
583
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300584 if (!intel_hdmi->has_hdmi_sink) {
585 I915_WRITE(reg, 0);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300586 POSTING_READ(reg);
Paulo Zanoni0c14c7f2012-05-28 16:42:49 -0300587 return;
588 }
589
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300590 val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
591 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW);
592
593 I915_WRITE(reg, val);
Paulo Zanoni9d9740f2012-05-28 16:43:00 -0300594 POSTING_READ(reg);
Paulo Zanoni0dd87d22012-05-28 16:42:53 -0300595
Paulo Zanoni687f4d02012-05-28 16:42:48 -0300596 intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
597 intel_hdmi_set_spd_infoframe(encoder);
598}
599
Daniel Vetterc59423a2013-07-21 21:37:04 +0200600static void intel_hdmi_mode_set(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800601{
Daniel Vetterc59423a2013-07-21 21:37:04 +0200602 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800603 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterc59423a2013-07-21 21:37:04 +0200604 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
605 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
606 struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300607 u32 hdmi_val;
Eric Anholt7d573822009-01-02 13:33:00 -0800608
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300609 hdmi_val = SDVO_ENCODING_HDMI;
Ville Syrjälä2af2c492013-06-25 14:16:34 +0300610 if (!HAS_PCH_SPLIT(dev))
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300611 hdmi_val |= intel_hdmi->color_range;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400612 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300613 hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
Adam Jacksonb599c0b2010-07-16 14:46:31 -0400614 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300615 hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
Eric Anholt7d573822009-01-02 13:33:00 -0800616
Daniel Vetterc59423a2013-07-21 21:37:04 +0200617 if (crtc->config.pipe_bpp > 24)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300618 hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700619 else
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300620 hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
Jesse Barnes020f6702011-06-24 12:19:25 -0700621
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800622 /* Required on CPT */
623 if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300624 hdmi_val |= HDMI_MODE_SELECT_HDMI;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800625
David Härdeman3c17fe42010-09-24 21:44:32 +0200626 if (intel_hdmi->has_audio) {
Wu Fengguange0dac652011-09-05 14:25:34 +0800627 DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
Daniel Vetterc59423a2013-07-21 21:37:04 +0200628 pipe_name(crtc->pipe));
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300629 hdmi_val |= SDVO_AUDIO_ENABLE;
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300630 hdmi_val |= HDMI_MODE_SELECT_HDMI;
Daniel Vetterc59423a2013-07-21 21:37:04 +0200631 intel_write_eld(&encoder->base, adjusted_mode);
David Härdeman3c17fe42010-09-24 21:44:32 +0200632 }
Eric Anholt7d573822009-01-02 13:33:00 -0800633
Jesse Barnes75770562011-10-12 09:01:58 -0700634 if (HAS_PCH_CPT(dev))
Daniel Vetterc59423a2013-07-21 21:37:04 +0200635 hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe);
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300636 else
Daniel Vetterc59423a2013-07-21 21:37:04 +0200637 hdmi_val |= SDVO_PIPE_SEL(crtc->pipe);
Eric Anholt7d573822009-01-02 13:33:00 -0800638
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300639 I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
640 POSTING_READ(intel_hdmi->hdmi_reg);
David Härdeman3c17fe42010-09-24 21:44:32 +0200641
Daniel Vetterc59423a2013-07-21 21:37:04 +0200642 intel_hdmi->set_infoframes(&encoder->base, adjusted_mode);
Eric Anholt7d573822009-01-02 13:33:00 -0800643}
644
Daniel Vetter85234cd2012-07-02 13:27:29 +0200645static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
646 enum pipe *pipe)
Eric Anholt7d573822009-01-02 13:33:00 -0800647{
Daniel Vetter85234cd2012-07-02 13:27:29 +0200648 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800649 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter85234cd2012-07-02 13:27:29 +0200650 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
651 u32 tmp;
652
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300653 tmp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter85234cd2012-07-02 13:27:29 +0200654
655 if (!(tmp & SDVO_ENABLE))
656 return false;
657
658 if (HAS_PCH_CPT(dev))
659 *pipe = PORT_TO_PIPE_CPT(tmp);
660 else
661 *pipe = PORT_TO_PIPE(tmp);
662
663 return true;
664}
665
Jesse Barnes045ac3b2013-05-14 17:08:26 -0700666static void intel_hdmi_get_config(struct intel_encoder *encoder,
667 struct intel_crtc_config *pipe_config)
668{
669 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
670 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
671 u32 tmp, flags = 0;
672
673 tmp = I915_READ(intel_hdmi->hdmi_reg);
674
675 if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
676 flags |= DRM_MODE_FLAG_PHSYNC;
677 else
678 flags |= DRM_MODE_FLAG_NHSYNC;
679
680 if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
681 flags |= DRM_MODE_FLAG_PVSYNC;
682 else
683 flags |= DRM_MODE_FLAG_NVSYNC;
684
685 pipe_config->adjusted_mode.flags |= flags;
686}
687
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200688static void intel_enable_hdmi(struct intel_encoder *encoder)
Eric Anholt7d573822009-01-02 13:33:00 -0800689{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200690 struct drm_device *dev = encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -0800691 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300692 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200693 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
Eric Anholt7d573822009-01-02 13:33:00 -0800694 u32 temp;
Wu Fengguang2deed762011-12-09 20:42:20 +0800695 u32 enable_bits = SDVO_ENABLE;
696
697 if (intel_hdmi->has_audio)
698 enable_bits |= SDVO_AUDIO_ENABLE;
Eric Anholt7d573822009-01-02 13:33:00 -0800699
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300700 temp = I915_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000701
Daniel Vetter7a87c282012-06-05 11:03:39 +0200702 /* HW workaround for IBX, we need to move the port to transcoder A
Paulo Zanonidc0fa712013-02-19 16:21:46 -0300703 * before disabling it, so restore the transcoder select bit here. */
704 if (HAS_PCH_IBX(dev))
705 enable_bits |= SDVO_PIPE_SEL(intel_crtc->pipe);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200706
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200707 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
708 * we do this anyway which shows more stable in testing.
709 */
710 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300711 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
712 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200713 }
Daniel Vetter7a87c282012-06-05 11:03:39 +0200714
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200715 temp |= enable_bits;
716
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300717 I915_WRITE(intel_hdmi->hdmi_reg, temp);
718 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200719
720 /* HW workaround, need to write this twice for issue that may result
721 * in first write getting masked.
722 */
723 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300724 I915_WRITE(intel_hdmi->hdmi_reg, temp);
725 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200726 }
Jani Nikulab76cf762013-07-30 12:20:31 +0300727}
Jesse Barnes89b667f2013-04-18 14:51:36 -0700728
Jani Nikulab76cf762013-07-30 12:20:31 +0300729static void vlv_enable_hdmi(struct intel_encoder *encoder)
730{
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200731}
732
733static void intel_disable_hdmi(struct intel_encoder *encoder)
734{
735 struct drm_device *dev = encoder->base.dev;
736 struct drm_i915_private *dev_priv = dev->dev_private;
737 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
738 u32 temp;
Wang Xingchao3cce5742012-09-13 11:19:00 +0800739 u32 enable_bits = SDVO_ENABLE | SDVO_AUDIO_ENABLE;
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200740
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300741 temp = I915_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200742
743 /* HW workaround for IBX, we need to move the port to transcoder A
744 * before disabling it. */
745 if (HAS_PCH_IBX(dev)) {
746 struct drm_crtc *crtc = encoder->base.crtc;
747 int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
748
749 if (temp & SDVO_PIPE_B_SELECT) {
750 temp &= ~SDVO_PIPE_B_SELECT;
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300751 I915_WRITE(intel_hdmi->hdmi_reg, temp);
752 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200753
754 /* Again we need to write this twice. */
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300755 I915_WRITE(intel_hdmi->hdmi_reg, temp);
756 POSTING_READ(intel_hdmi->hdmi_reg);
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200757
758 /* Transcoder selection bits only update
759 * effectively on vblank. */
760 if (crtc)
761 intel_wait_for_vblank(dev, pipe);
762 else
763 msleep(50);
Daniel Vetter7a87c282012-06-05 11:03:39 +0200764 }
765 }
766
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000767 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
768 * we do this anyway which shows more stable in testing.
769 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800770 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300771 I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
772 POSTING_READ(intel_hdmi->hdmi_reg);
Eric Anholt7d573822009-01-02 13:33:00 -0800773 }
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000774
Daniel Vetter5ab432e2012-06-30 08:59:56 +0200775 temp &= ~enable_bits;
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000776
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300777 I915_WRITE(intel_hdmi->hdmi_reg, temp);
778 POSTING_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000779
780 /* HW workaround, need to write this twice for issue that may result
781 * in first write getting masked.
782 */
Eric Anholtc619eed2010-01-28 16:45:52 -0800783 if (HAS_PCH_SPLIT(dev)) {
Paulo Zanonib242b7f2013-02-18 19:00:26 -0300784 I915_WRITE(intel_hdmi->hdmi_reg, temp);
785 POSTING_READ(intel_hdmi->hdmi_reg);
Zhenyu Wangd8a2d0e2009-11-02 07:52:30 +0000786 }
Eric Anholt7d573822009-01-02 13:33:00 -0800787}
788
Eric Anholt7d573822009-01-02 13:33:00 -0800789static int intel_hdmi_mode_valid(struct drm_connector *connector,
790 struct drm_display_mode *mode)
791{
792 if (mode->clock > 165000)
793 return MODE_CLOCK_HIGH;
794 if (mode->clock < 20000)
Nicolas Kaiser5cbba412011-05-30 12:48:26 +0200795 return MODE_CLOCK_LOW;
Eric Anholt7d573822009-01-02 13:33:00 -0800796
797 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
798 return MODE_NO_DBLESCAN;
799
800 return MODE_OK;
801}
802
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100803bool intel_hdmi_compute_config(struct intel_encoder *encoder,
804 struct intel_crtc_config *pipe_config)
Eric Anholt7d573822009-01-02 13:33:00 -0800805{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100806 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
807 struct drm_device *dev = encoder->base.dev;
808 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
Daniel Vetter325b9d02013-04-19 11:24:33 +0200809 int clock_12bpc = pipe_config->requested_mode.clock * 3 / 2;
Daniel Vettere29c22c2013-02-21 00:00:16 +0100810 int desired_bpp;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200811
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200812 if (intel_hdmi->color_range_auto) {
813 /* See CEA-861-E - 5.1 Default Encoding Parameters */
814 if (intel_hdmi->has_hdmi_sink &&
Thierry Reding18316c82012-12-20 15:41:44 +0100815 drm_match_cea_mode(adjusted_mode) > 1)
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300816 intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200817 else
818 intel_hdmi->color_range = 0;
819 }
820
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200821 if (intel_hdmi->color_range)
Daniel Vetter50f3b012013-03-27 00:44:56 +0100822 pipe_config->limited_color_range = true;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +0200823
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +0100824 if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev))
825 pipe_config->has_pch_encoder = true;
826
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100827 /*
828 * HDMI is either 12 or 8, so if the display lets 10bpc sneak
829 * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
Daniel Vetter325b9d02013-04-19 11:24:33 +0200830 * outputs. We also need to check that the higher clock still fits
831 * within limits.
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100832 */
Daniel Vetter325b9d02013-04-19 11:24:33 +0200833 if (pipe_config->pipe_bpp > 8*3 && clock_12bpc <= 225000
834 && HAS_PCH_SPLIT(dev)) {
Daniel Vettere29c22c2013-02-21 00:00:16 +0100835 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
836 desired_bpp = 12*3;
Daniel Vetter325b9d02013-04-19 11:24:33 +0200837
838 /* Need to adjust the port link by 1.5x for 12bpc. */
Daniel Vetterff9a6752013-06-01 17:16:21 +0200839 pipe_config->port_clock = clock_12bpc;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100840 } else {
Daniel Vettere29c22c2013-02-21 00:00:16 +0100841 DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
842 desired_bpp = 8*3;
843 }
844
845 if (!pipe_config->bw_constrained) {
846 DRM_DEBUG_KMS("forcing pipe bpc to %i for HDMI\n", desired_bpp);
847 pipe_config->pipe_bpp = desired_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +0100848 }
849
Daniel Vetter325b9d02013-04-19 11:24:33 +0200850 if (adjusted_mode->clock > 225000) {
851 DRM_DEBUG_KMS("too high HDMI clock, rejecting mode\n");
852 return false;
853 }
854
Eric Anholt7d573822009-01-02 13:33:00 -0800855 return true;
856}
857
Keith Packardaa93d632009-05-05 09:52:46 -0700858static enum drm_connector_status
Chris Wilson930a9e22010-09-14 11:07:23 +0100859intel_hdmi_detect(struct drm_connector *connector, bool force)
Ma Ling9dff6af2009-04-02 13:13:26 +0800860{
Damien Lespiaub0ea7d32012-12-13 16:09:00 +0000861 struct drm_device *dev = connector->dev;
Chris Wilsondf0e9242010-09-09 16:20:55 +0100862 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonid63885d2012-10-26 19:05:49 -0200863 struct intel_digital_port *intel_dig_port =
864 hdmi_to_dig_port(intel_hdmi);
865 struct intel_encoder *intel_encoder = &intel_dig_port->base;
Damien Lespiaub0ea7d32012-12-13 16:09:00 +0000866 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700867 struct edid *edid;
Keith Packardaa93d632009-05-05 09:52:46 -0700868 enum drm_connector_status status = connector_status_disconnected;
Ma Ling9dff6af2009-04-02 13:13:26 +0800869
Chris Wilson164c8592013-07-20 20:27:08 +0100870 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
871 connector->base.id, drm_get_connector_name(connector));
872
Chris Wilsonea5b2132010-08-04 13:50:23 +0100873 intel_hdmi->has_hdmi_sink = false;
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800874 intel_hdmi->has_audio = false;
Ville Syrjäläabedc072013-01-17 16:31:31 +0200875 intel_hdmi->rgb_quant_range_selectable = false;
Chris Wilsonf899fc62010-07-20 15:44:45 -0700876 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800877 intel_gmbus_get_adapter(dev_priv,
878 intel_hdmi->ddc_bus));
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800879
Keith Packardaa93d632009-05-05 09:52:46 -0700880 if (edid) {
Eric Anholtbe9f1c42009-06-21 22:14:55 -0700881 if (edid->input & DRM_EDID_INPUT_DIGITAL) {
Keith Packardaa93d632009-05-05 09:52:46 -0700882 status = connector_status_connected;
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800883 if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
884 intel_hdmi->has_hdmi_sink =
885 drm_detect_hdmi_monitor(edid);
Zhenyu Wang2e3d6002010-09-10 10:39:40 +0800886 intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
Ville Syrjäläabedc072013-01-17 16:31:31 +0200887 intel_hdmi->rgb_quant_range_selectable =
888 drm_rgb_quant_range_selectable(edid);
Keith Packardaa93d632009-05-05 09:52:46 -0700889 }
Keith Packardaa93d632009-05-05 09:52:46 -0700890 kfree(edid);
Ma Ling9dff6af2009-04-02 13:13:26 +0800891 }
ling.ma@intel.com2ded9e22009-07-16 17:23:09 +0800892
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100893 if (status == connector_status_connected) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800894 if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
895 intel_hdmi->has_audio =
896 (intel_hdmi->force_audio == HDMI_AUDIO_ON);
Paulo Zanonid63885d2012-10-26 19:05:49 -0200897 intel_encoder->type = INTEL_OUTPUT_HDMI;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100898 }
899
Keith Packardaa93d632009-05-05 09:52:46 -0700900 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +0800901}
902
Eric Anholt7d573822009-01-02 13:33:00 -0800903static int intel_hdmi_get_modes(struct drm_connector *connector)
904{
Chris Wilsondf0e9242010-09-09 16:20:55 +0100905 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Chris Wilsonf899fc62010-07-20 15:44:45 -0700906 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt7d573822009-01-02 13:33:00 -0800907
908 /* We should parse the EDID data and find out if it's an HDMI sink so
909 * we can send audio to it.
910 */
911
Chris Wilsonf899fc62010-07-20 15:44:45 -0700912 return intel_ddc_get_modes(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800913 intel_gmbus_get_adapter(dev_priv,
914 intel_hdmi->ddc_bus));
Eric Anholt7d573822009-01-02 13:33:00 -0800915}
916
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000917static bool
918intel_hdmi_detect_audio(struct drm_connector *connector)
919{
920 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
921 struct drm_i915_private *dev_priv = connector->dev->dev_private;
922 struct edid *edid;
923 bool has_audio = false;
924
925 edid = drm_get_edid(connector,
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800926 intel_gmbus_get_adapter(dev_priv,
927 intel_hdmi->ddc_bus));
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000928 if (edid) {
929 if (edid->input & DRM_EDID_INPUT_DIGITAL)
930 has_audio = drm_detect_monitor_audio(edid);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000931 kfree(edid);
932 }
933
934 return has_audio;
935}
936
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100937static int
938intel_hdmi_set_property(struct drm_connector *connector,
Paulo Zanonied517fb2012-05-14 17:12:50 -0300939 struct drm_property *property,
940 uint64_t val)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100941{
942 struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
Paulo Zanonida63a9f2012-10-26 19:05:46 -0200943 struct intel_digital_port *intel_dig_port =
944 hdmi_to_dig_port(intel_hdmi);
Chris Wilsone953fd72011-02-21 22:23:52 +0000945 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100946 int ret;
947
Rob Clark662595d2012-10-11 20:36:04 -0500948 ret = drm_object_property_set_value(&connector->base, property, val);
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100949 if (ret)
950 return ret;
951
Chris Wilson3f43c482011-05-12 22:17:24 +0100952 if (property == dev_priv->force_audio_property) {
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800953 enum hdmi_force_audio i = val;
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000954 bool has_audio;
955
956 if (i == intel_hdmi->force_audio)
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100957 return 0;
958
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000959 intel_hdmi->force_audio = i;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100960
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800961 if (i == HDMI_AUDIO_AUTO)
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000962 has_audio = intel_hdmi_detect_audio(connector);
963 else
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800964 has_audio = (i == HDMI_AUDIO_ON);
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000965
Wu Fengguangb1d7e4b2012-02-14 11:45:36 +0800966 if (i == HDMI_AUDIO_OFF_DVI)
967 intel_hdmi->has_hdmi_sink = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100968
Chris Wilson1aad7ac2011-02-09 18:46:58 +0000969 intel_hdmi->has_audio = has_audio;
Chris Wilson55b7d6e82010-09-19 09:29:33 +0100970 goto done;
971 }
972
Chris Wilsone953fd72011-02-21 22:23:52 +0000973 if (property == dev_priv->broadcast_rgb_property) {
Daniel Vetterae4edb82013-04-22 17:07:23 +0200974 bool old_auto = intel_hdmi->color_range_auto;
975 uint32_t old_range = intel_hdmi->color_range;
976
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200977 switch (val) {
978 case INTEL_BROADCAST_RGB_AUTO:
979 intel_hdmi->color_range_auto = true;
980 break;
981 case INTEL_BROADCAST_RGB_FULL:
982 intel_hdmi->color_range_auto = false;
983 intel_hdmi->color_range = 0;
984 break;
985 case INTEL_BROADCAST_RGB_LIMITED:
986 intel_hdmi->color_range_auto = false;
Paulo Zanoni4f3a8bc2013-02-19 16:21:47 -0300987 intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
Ville Syrjälä55bc60d2013-01-17 16:31:29 +0200988 break;
989 default:
990 return -EINVAL;
991 }
Daniel Vetterae4edb82013-04-22 17:07:23 +0200992
993 if (old_auto == intel_hdmi->color_range_auto &&
994 old_range == intel_hdmi->color_range)
995 return 0;
996
Chris Wilsone953fd72011-02-21 22:23:52 +0000997 goto done;
998 }
999
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001000 return -EINVAL;
1001
1002done:
Chris Wilsonc0c36b942012-12-19 16:08:43 +00001003 if (intel_dig_port->base.base.crtc)
1004 intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001005
1006 return 0;
1007}
1008
Jesse Barnes89b667f2013-04-18 14:51:36 -07001009static void intel_hdmi_pre_enable(struct intel_encoder *encoder)
1010{
1011 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1012 struct drm_device *dev = encoder->base.dev;
1013 struct drm_i915_private *dev_priv = dev->dev_private;
1014 struct intel_crtc *intel_crtc =
1015 to_intel_crtc(encoder->base.crtc);
1016 int port = vlv_dport_to_channel(dport);
1017 int pipe = intel_crtc->pipe;
1018 u32 val;
1019
1020 if (!IS_VALLEYVIEW(dev))
1021 return;
1022
Jesse Barnes89b667f2013-04-18 14:51:36 -07001023 /* Enable clock channels for this port */
Chris Wilson0980a602013-07-26 19:57:35 +01001024 mutex_lock(&dev_priv->dpio_lock);
Jani Nikulaae992582013-05-22 15:36:19 +03001025 val = vlv_dpio_read(dev_priv, DPIO_DATA_LANE_A(port));
Jesse Barnes89b667f2013-04-18 14:51:36 -07001026 val = 0;
1027 if (pipe)
1028 val |= (1<<21);
1029 else
1030 val &= ~(1<<21);
1031 val |= 0x001000c4;
Jani Nikulaae992582013-05-22 15:36:19 +03001032 vlv_dpio_write(dev_priv, DPIO_DATA_CHANNEL(port), val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001033
1034 /* HDMI 1.0V-2dB */
Jani Nikulaae992582013-05-22 15:36:19 +03001035 vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port), 0);
1036 vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL4(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001037 0x2b245f5f);
Jani Nikulaae992582013-05-22 15:36:19 +03001038 vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL2(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001039 0x5578b83a);
Jani Nikulaae992582013-05-22 15:36:19 +03001040 vlv_dpio_write(dev_priv, DPIO_TX_SWING_CTL3(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001041 0x0c782040);
Jani Nikulaae992582013-05-22 15:36:19 +03001042 vlv_dpio_write(dev_priv, DPIO_TX3_SWING_CTL4(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001043 0x2b247878);
Jani Nikulaae992582013-05-22 15:36:19 +03001044 vlv_dpio_write(dev_priv, DPIO_PCS_STAGGER0(port), 0x00030000);
1045 vlv_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001046 0x00002000);
Jani Nikulaae992582013-05-22 15:36:19 +03001047 vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001048 DPIO_TX_OCALINIT_EN);
1049
1050 /* Program lane clock */
Jani Nikulaae992582013-05-22 15:36:19 +03001051 vlv_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF0(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001052 0x00760018);
Jani Nikulaae992582013-05-22 15:36:19 +03001053 vlv_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF8(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001054 0x00400888);
Chris Wilson0980a602013-07-26 19:57:35 +01001055 mutex_unlock(&dev_priv->dpio_lock);
Jani Nikulab76cf762013-07-30 12:20:31 +03001056
1057 intel_enable_hdmi(encoder);
1058
1059 vlv_wait_port_ready(dev_priv, port);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001060}
1061
1062static void intel_hdmi_pre_pll_enable(struct intel_encoder *encoder)
1063{
1064 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1065 struct drm_device *dev = encoder->base.dev;
1066 struct drm_i915_private *dev_priv = dev->dev_private;
1067 int port = vlv_dport_to_channel(dport);
1068
1069 if (!IS_VALLEYVIEW(dev))
1070 return;
1071
Jesse Barnes89b667f2013-04-18 14:51:36 -07001072 /* Program Tx lane resets to default */
Chris Wilson0980a602013-07-26 19:57:35 +01001073 mutex_lock(&dev_priv->dpio_lock);
Jani Nikulaae992582013-05-22 15:36:19 +03001074 vlv_dpio_write(dev_priv, DPIO_PCS_TX(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001075 DPIO_PCS_TX_LANE2_RESET |
1076 DPIO_PCS_TX_LANE1_RESET);
Jani Nikulaae992582013-05-22 15:36:19 +03001077 vlv_dpio_write(dev_priv, DPIO_PCS_CLK(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001078 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1079 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1080 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1081 DPIO_PCS_CLK_SOFT_RESET);
1082
1083 /* Fix up inter-pair skew failure */
Jani Nikulaae992582013-05-22 15:36:19 +03001084 vlv_dpio_write(dev_priv, DPIO_PCS_STAGGER1(port), 0x00750f00);
1085 vlv_dpio_write(dev_priv, DPIO_TX_CTL(port), 0x00001500);
1086 vlv_dpio_write(dev_priv, DPIO_TX_LANE(port), 0x40400000);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001087
Jani Nikulaae992582013-05-22 15:36:19 +03001088 vlv_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001089 0x00002000);
Jani Nikulaae992582013-05-22 15:36:19 +03001090 vlv_dpio_write(dev_priv, DPIO_TX_OCALINIT(port),
Jesse Barnes89b667f2013-04-18 14:51:36 -07001091 DPIO_TX_OCALINIT_EN);
Chris Wilson0980a602013-07-26 19:57:35 +01001092 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001093}
1094
1095static void intel_hdmi_post_disable(struct intel_encoder *encoder)
1096{
1097 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1098 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1099 int port = vlv_dport_to_channel(dport);
1100
1101 /* Reset lanes to avoid HDMI flicker (VLV w/a) */
1102 mutex_lock(&dev_priv->dpio_lock);
Jani Nikulaae992582013-05-22 15:36:19 +03001103 vlv_dpio_write(dev_priv, DPIO_PCS_TX(port), 0x00000000);
1104 vlv_dpio_write(dev_priv, DPIO_PCS_CLK(port), 0x00e00060);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001105 mutex_unlock(&dev_priv->dpio_lock);
1106}
1107
Eric Anholt7d573822009-01-02 13:33:00 -08001108static void intel_hdmi_destroy(struct drm_connector *connector)
1109{
Eric Anholt7d573822009-01-02 13:33:00 -08001110 drm_sysfs_connector_remove(connector);
1111 drm_connector_cleanup(connector);
Zhenyu Wang674e2d02010-03-29 15:57:42 +08001112 kfree(connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001113}
1114
Eric Anholt7d573822009-01-02 13:33:00 -08001115static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001116 .dpms = intel_connector_dpms,
Eric Anholt7d573822009-01-02 13:33:00 -08001117 .detect = intel_hdmi_detect,
1118 .fill_modes = drm_helper_probe_single_connector_modes,
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001119 .set_property = intel_hdmi_set_property,
Eric Anholt7d573822009-01-02 13:33:00 -08001120 .destroy = intel_hdmi_destroy,
1121};
1122
1123static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
1124 .get_modes = intel_hdmi_get_modes,
1125 .mode_valid = intel_hdmi_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +01001126 .best_encoder = intel_best_encoder,
Eric Anholt7d573822009-01-02 13:33:00 -08001127};
1128
Eric Anholt7d573822009-01-02 13:33:00 -08001129static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +01001130 .destroy = intel_encoder_destroy,
Eric Anholt7d573822009-01-02 13:33:00 -08001131};
1132
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001133static void
1134intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
1135{
Chris Wilson3f43c482011-05-12 22:17:24 +01001136 intel_attach_force_audio_property(connector);
Chris Wilsone953fd72011-02-21 22:23:52 +00001137 intel_attach_broadcast_rgb_property(connector);
Ville Syrjälä55bc60d2013-01-17 16:31:29 +02001138 intel_hdmi->color_range_auto = true;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001139}
1140
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001141void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1142 struct intel_connector *intel_connector)
Eric Anholt7d573822009-01-02 13:33:00 -08001143{
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001144 struct drm_connector *connector = &intel_connector->base;
1145 struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
1146 struct intel_encoder *intel_encoder = &intel_dig_port->base;
1147 struct drm_device *dev = intel_encoder->base.dev;
Eric Anholt7d573822009-01-02 13:33:00 -08001148 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001149 enum port port = intel_dig_port->port;
Eric Anholt7d573822009-01-02 13:33:00 -08001150
Eric Anholt7d573822009-01-02 13:33:00 -08001151 drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
Adam Jackson8d911042009-09-23 15:08:29 -04001152 DRM_MODE_CONNECTOR_HDMIA);
Eric Anholt7d573822009-01-02 13:33:00 -08001153 drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
1154
Peter Rossc3febcc2012-01-28 14:49:26 +01001155 connector->interlace_allowed = 1;
Eric Anholt7d573822009-01-02 13:33:00 -08001156 connector->doublescan_allowed = 0;
1157
Daniel Vetter08d644a2012-07-12 20:19:59 +02001158 switch (port) {
1159 case PORT_B:
Chris Wilsonf899fc62010-07-20 15:44:45 -07001160 intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
Egbert Eich1d843f92013-02-25 12:06:49 -05001161 intel_encoder->hpd_pin = HPD_PORT_B;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001162 break;
1163 case PORT_C:
Chris Wilsonf899fc62010-07-20 15:44:45 -07001164 intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
Egbert Eich1d843f92013-02-25 12:06:49 -05001165 intel_encoder->hpd_pin = HPD_PORT_C;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001166 break;
1167 case PORT_D:
Chris Wilsonf899fc62010-07-20 15:44:45 -07001168 intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
Egbert Eich1d843f92013-02-25 12:06:49 -05001169 intel_encoder->hpd_pin = HPD_PORT_D;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001170 break;
1171 case PORT_A:
Egbert Eich1d843f92013-02-25 12:06:49 -05001172 intel_encoder->hpd_pin = HPD_PORT_A;
Daniel Vetter08d644a2012-07-12 20:19:59 +02001173 /* Internal port only for eDP. */
1174 default:
Eugeni Dodonov6e4c1672012-05-09 15:37:13 -03001175 BUG();
Ma Lingf8aed702009-08-24 13:50:24 +08001176 }
Eric Anholt7d573822009-01-02 13:33:00 -08001177
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001178 if (IS_VALLEYVIEW(dev)) {
Shobhit Kumar90b107c2012-03-28 13:39:32 -07001179 intel_hdmi->write_infoframe = vlv_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001180 intel_hdmi->set_infoframes = vlv_set_infoframes;
Jesse Barnes7637bfd2013-03-08 10:46:01 -08001181 } else if (!HAS_PCH_SPLIT(dev)) {
1182 intel_hdmi->write_infoframe = g4x_write_infoframe;
1183 intel_hdmi->set_infoframes = g4x_set_infoframes;
Paulo Zanoni22b8bf12013-02-18 19:00:23 -03001184 } else if (HAS_DDI(dev)) {
Eugeni Dodonov8c5f5f72012-05-10 10:18:02 -03001185 intel_hdmi->write_infoframe = hsw_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001186 intel_hdmi->set_infoframes = hsw_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001187 } else if (HAS_PCH_IBX(dev)) {
1188 intel_hdmi->write_infoframe = ibx_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001189 intel_hdmi->set_infoframes = ibx_set_infoframes;
Paulo Zanonifdf12502012-05-04 17:18:24 -03001190 } else {
1191 intel_hdmi->write_infoframe = cpt_write_infoframe;
Paulo Zanoni687f4d02012-05-28 16:42:48 -03001192 intel_hdmi->set_infoframes = cpt_set_infoframes;
Jesse Barnes64a8fc02011-09-22 11:16:00 +05301193 }
Jesse Barnes45187ac2011-08-03 09:22:55 -07001194
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001195 if (HAS_DDI(dev))
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001196 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
1197 else
1198 intel_connector->get_hw_state = intel_connector_get_hw_state;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001199
1200 intel_hdmi_add_properties(intel_hdmi, connector);
1201
1202 intel_connector_attach_encoder(intel_connector, intel_encoder);
1203 drm_sysfs_connector_add(connector);
1204
1205 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1206 * 0xd. Failure to do so will result in spurious interrupts being
1207 * generated on the port when a cable is not attached.
1208 */
1209 if (IS_G4X(dev) && !IS_GM45(dev)) {
1210 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
1211 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
1212 }
1213}
1214
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001215void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port)
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001216{
1217 struct intel_digital_port *intel_dig_port;
1218 struct intel_encoder *intel_encoder;
1219 struct drm_encoder *encoder;
1220 struct intel_connector *intel_connector;
1221
1222 intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL);
1223 if (!intel_dig_port)
1224 return;
1225
1226 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
1227 if (!intel_connector) {
1228 kfree(intel_dig_port);
1229 return;
1230 }
1231
1232 intel_encoder = &intel_dig_port->base;
1233 encoder = &intel_encoder->base;
1234
1235 drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
1236 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001237
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01001238 intel_encoder->compute_config = intel_hdmi_compute_config;
Daniel Vetterc59423a2013-07-21 21:37:04 +02001239 intel_encoder->mode_set = intel_hdmi_mode_set;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001240 intel_encoder->disable = intel_disable_hdmi;
1241 intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07001242 intel_encoder->get_config = intel_hdmi_get_config;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001243 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -07001244 intel_encoder->pre_pll_enable = intel_hdmi_pre_pll_enable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001245 intel_encoder->pre_enable = intel_hdmi_pre_enable;
1246 intel_encoder->enable = vlv_enable_hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001247 intel_encoder->post_disable = intel_hdmi_post_disable;
Jani Nikulab76cf762013-07-30 12:20:31 +03001248 } else {
1249 intel_encoder->enable = intel_enable_hdmi;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001250 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001251
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001252 intel_encoder->type = INTEL_OUTPUT_HDMI;
1253 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
1254 intel_encoder->cloneable = false;
Eric Anholt7d573822009-01-02 13:33:00 -08001255
Paulo Zanoni174edf12012-10-26 19:05:50 -02001256 intel_dig_port->port = port;
Paulo Zanonib242b7f2013-02-18 19:00:26 -03001257 intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001258 intel_dig_port->dp.output_reg = 0;
Chris Wilson55b7d6e82010-09-19 09:29:33 +01001259
Paulo Zanonib9cb2342012-10-26 19:05:47 -02001260 intel_hdmi_init_connector(intel_dig_port, intel_connector);
Eric Anholt7d573822009-01-02 13:33:00 -08001261}