Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 1 | /* |
| 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 31 | #include <linux/delay.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 32 | #include <drm/drmP.h> |
| 33 | #include <drm/drm_crtc.h> |
| 34 | #include <drm/drm_edid.h> |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 35 | #include "intel_drv.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 36 | #include <drm/i915_drm.h> |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 37 | #include "i915_drv.h" |
| 38 | |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 39 | static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi) |
| 40 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 41 | return hdmi_to_dig_port(intel_hdmi)->base.base.dev; |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 42 | } |
| 43 | |
Daniel Vetter | afba018 | 2012-06-12 16:36:45 +0200 | [diff] [blame] | 44 | static void |
| 45 | assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi) |
| 46 | { |
Paulo Zanoni | 30add22 | 2012-10-26 19:05:45 -0200 | [diff] [blame] | 47 | struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi); |
Daniel Vetter | afba018 | 2012-06-12 16:36:45 +0200 | [diff] [blame] | 48 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 49 | uint32_t enabled_bits; |
| 50 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 51 | enabled_bits = HAS_DDI(dev) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE; |
Daniel Vetter | afba018 | 2012-06-12 16:36:45 +0200 | [diff] [blame] | 52 | |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 53 | WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits, |
Daniel Vetter | afba018 | 2012-06-12 16:36:45 +0200 | [diff] [blame] | 54 | "HDMI port enabled, expecting disabled\n"); |
| 55 | } |
| 56 | |
Eugeni Dodonov | f5bbfca | 2012-05-09 15:37:30 -0300 | [diff] [blame] | 57 | struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder) |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 58 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 59 | struct intel_digital_port *intel_dig_port = |
| 60 | container_of(encoder, struct intel_digital_port, base.base); |
| 61 | return &intel_dig_port->hdmi; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 64 | static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector) |
| 65 | { |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 66 | return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base); |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 69 | void intel_dip_infoframe_csum(struct dip_infoframe *frame) |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 70 | { |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 71 | uint8_t *data = (uint8_t *)frame; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 72 | uint8_t sum = 0; |
| 73 | unsigned i; |
| 74 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 75 | frame->checksum = 0; |
| 76 | frame->ecc = 0; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 77 | |
Jesse Barnes | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 78 | for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++) |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 79 | sum += data[i]; |
| 80 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 81 | frame->checksum = 0x100 - sum; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 84 | static u32 g4x_infoframe_index(struct dip_infoframe *frame) |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 85 | { |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 86 | switch (frame->type) { |
| 87 | case DIP_TYPE_AVI: |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 88 | return VIDEO_DIP_SELECT_AVI; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 89 | case DIP_TYPE_SPD: |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 90 | return VIDEO_DIP_SELECT_SPD; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 91 | default: |
| 92 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 93 | return 0; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 94 | } |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 97 | static u32 g4x_infoframe_enable(struct dip_infoframe *frame) |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 98 | { |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 99 | switch (frame->type) { |
| 100 | case DIP_TYPE_AVI: |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 101 | return VIDEO_DIP_ENABLE_AVI; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 102 | case DIP_TYPE_SPD: |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 103 | return VIDEO_DIP_ENABLE_SPD; |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 104 | default: |
| 105 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 106 | return 0; |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 107 | } |
Paulo Zanoni | fa193ff | 2012-05-04 17:18:20 -0300 | [diff] [blame] | 108 | } |
| 109 | |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 110 | static u32 hsw_infoframe_enable(struct dip_infoframe *frame) |
| 111 | { |
| 112 | switch (frame->type) { |
| 113 | case DIP_TYPE_AVI: |
| 114 | return VIDEO_DIP_ENABLE_AVI_HSW; |
| 115 | case DIP_TYPE_SPD: |
| 116 | return VIDEO_DIP_ENABLE_SPD_HSW; |
| 117 | default: |
| 118 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
| 119 | return 0; |
| 120 | } |
| 121 | } |
| 122 | |
Rodrigo Vivi | 7d9bceb | 2013-02-25 19:55:16 -0300 | [diff] [blame] | 123 | static u32 hsw_infoframe_data_reg(struct dip_infoframe *frame, |
| 124 | enum transcoder cpu_transcoder) |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 125 | { |
| 126 | switch (frame->type) { |
| 127 | case DIP_TYPE_AVI: |
Rodrigo Vivi | 7d9bceb | 2013-02-25 19:55:16 -0300 | [diff] [blame] | 128 | return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder); |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 129 | case DIP_TYPE_SPD: |
Rodrigo Vivi | 7d9bceb | 2013-02-25 19:55:16 -0300 | [diff] [blame] | 130 | return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder); |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 131 | default: |
| 132 | DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type); |
| 133 | return 0; |
| 134 | } |
| 135 | } |
| 136 | |
Daniel Vetter | a3da1df | 2012-05-08 15:19:06 +0200 | [diff] [blame] | 137 | static void g4x_write_infoframe(struct drm_encoder *encoder, |
| 138 | struct dip_infoframe *frame) |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 139 | { |
| 140 | uint32_t *data = (uint32_t *)frame; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 141 | struct drm_device *dev = encoder->dev; |
| 142 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 143 | u32 val = I915_READ(VIDEO_DIP_CTL); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 144 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 145 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 146 | WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n"); |
| 147 | |
Paulo Zanoni | 1d4f85a | 2012-05-04 17:18:18 -0300 | [diff] [blame] | 148 | val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */ |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 149 | val |= g4x_infoframe_index(frame); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 150 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 151 | val &= ~g4x_infoframe_enable(frame); |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 152 | |
| 153 | I915_WRITE(VIDEO_DIP_CTL, val); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 154 | |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 155 | mmiowb(); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 156 | for (i = 0; i < len; i += 4) { |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 157 | I915_WRITE(VIDEO_DIP_DATA, *data); |
| 158 | data++; |
| 159 | } |
Paulo Zanoni | adf00b2 | 2012-09-25 13:23:34 -0300 | [diff] [blame] | 160 | /* Write every possible data byte to force correct ECC calculation. */ |
| 161 | for (; i < VIDEO_DIP_DATA_SIZE; i += 4) |
| 162 | I915_WRITE(VIDEO_DIP_DATA, 0); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 163 | mmiowb(); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 164 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 165 | val |= g4x_infoframe_enable(frame); |
Paulo Zanoni | 60c5ea2 | 2012-05-04 17:18:22 -0300 | [diff] [blame] | 166 | val &= ~VIDEO_DIP_FREQ_MASK; |
Daniel Vetter | 4b24c93 | 2012-05-08 14:41:00 +0200 | [diff] [blame] | 167 | val |= VIDEO_DIP_FREQ_VSYNC; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 168 | |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 169 | I915_WRITE(VIDEO_DIP_CTL, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 170 | POSTING_READ(VIDEO_DIP_CTL); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 173 | static void ibx_write_infoframe(struct drm_encoder *encoder, |
| 174 | struct dip_infoframe *frame) |
| 175 | { |
| 176 | uint32_t *data = (uint32_t *)frame; |
| 177 | struct drm_device *dev = encoder->dev; |
| 178 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 179 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 180 | int reg = TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 181 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
| 182 | u32 val = I915_READ(reg); |
| 183 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 184 | WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n"); |
| 185 | |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 186 | val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */ |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 187 | val |= g4x_infoframe_index(frame); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 188 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 189 | val &= ~g4x_infoframe_enable(frame); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 190 | |
| 191 | I915_WRITE(reg, val); |
| 192 | |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 193 | mmiowb(); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 194 | for (i = 0; i < len; i += 4) { |
| 195 | I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data); |
| 196 | data++; |
| 197 | } |
Paulo Zanoni | adf00b2 | 2012-09-25 13:23:34 -0300 | [diff] [blame] | 198 | /* Write every possible data byte to force correct ECC calculation. */ |
| 199 | for (; i < VIDEO_DIP_DATA_SIZE; i += 4) |
| 200 | I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 201 | mmiowb(); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 202 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 203 | val |= g4x_infoframe_enable(frame); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 204 | val &= ~VIDEO_DIP_FREQ_MASK; |
Daniel Vetter | 4b24c93 | 2012-05-08 14:41:00 +0200 | [diff] [blame] | 205 | val |= VIDEO_DIP_FREQ_VSYNC; |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 206 | |
| 207 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 208 | POSTING_READ(reg); |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | static void cpt_write_infoframe(struct drm_encoder *encoder, |
| 212 | struct dip_infoframe *frame) |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 213 | { |
| 214 | uint32_t *data = (uint32_t *)frame; |
| 215 | struct drm_device *dev = encoder->dev; |
| 216 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 217 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 218 | int reg = TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 219 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 220 | u32 val = I915_READ(reg); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 221 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 222 | WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n"); |
| 223 | |
Jesse Barnes | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 224 | val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */ |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 225 | val |= g4x_infoframe_index(frame); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 226 | |
Paulo Zanoni | ecb9785 | 2012-05-04 17:18:21 -0300 | [diff] [blame] | 227 | /* The DIP control register spec says that we need to update the AVI |
| 228 | * infoframe without clearing its enable bit */ |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 229 | if (frame->type != DIP_TYPE_AVI) |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 230 | val &= ~g4x_infoframe_enable(frame); |
Paulo Zanoni | ecb9785 | 2012-05-04 17:18:21 -0300 | [diff] [blame] | 231 | |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 232 | I915_WRITE(reg, val); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 233 | |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 234 | mmiowb(); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 235 | for (i = 0; i < len; i += 4) { |
| 236 | I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data); |
| 237 | data++; |
| 238 | } |
Paulo Zanoni | adf00b2 | 2012-09-25 13:23:34 -0300 | [diff] [blame] | 239 | /* Write every possible data byte to force correct ECC calculation. */ |
| 240 | for (; i < VIDEO_DIP_DATA_SIZE; i += 4) |
| 241 | I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 242 | mmiowb(); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 243 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 244 | val |= g4x_infoframe_enable(frame); |
Paulo Zanoni | 60c5ea2 | 2012-05-04 17:18:22 -0300 | [diff] [blame] | 245 | val &= ~VIDEO_DIP_FREQ_MASK; |
Daniel Vetter | 4b24c93 | 2012-05-08 14:41:00 +0200 | [diff] [blame] | 246 | val |= VIDEO_DIP_FREQ_VSYNC; |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 247 | |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 248 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 249 | POSTING_READ(reg); |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 250 | } |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 251 | |
| 252 | static void vlv_write_infoframe(struct drm_encoder *encoder, |
| 253 | struct dip_infoframe *frame) |
| 254 | { |
| 255 | uint32_t *data = (uint32_t *)frame; |
| 256 | struct drm_device *dev = encoder->dev; |
| 257 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 258 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 259 | int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 260 | unsigned i, len = DIP_HEADER_SIZE + frame->len; |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 261 | u32 val = I915_READ(reg); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 262 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 263 | WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n"); |
| 264 | |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 265 | val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */ |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 266 | val |= g4x_infoframe_index(frame); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 267 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 268 | val &= ~g4x_infoframe_enable(frame); |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 269 | |
| 270 | I915_WRITE(reg, val); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 271 | |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 272 | mmiowb(); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 273 | for (i = 0; i < len; i += 4) { |
| 274 | I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data); |
| 275 | data++; |
| 276 | } |
Paulo Zanoni | adf00b2 | 2012-09-25 13:23:34 -0300 | [diff] [blame] | 277 | /* Write every possible data byte to force correct ECC calculation. */ |
| 278 | for (; i < VIDEO_DIP_DATA_SIZE; i += 4) |
| 279 | I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 280 | mmiowb(); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 281 | |
Daniel Vetter | bc2481f | 2012-05-08 15:18:32 +0200 | [diff] [blame] | 282 | val |= g4x_infoframe_enable(frame); |
Paulo Zanoni | 60c5ea2 | 2012-05-04 17:18:22 -0300 | [diff] [blame] | 283 | val &= ~VIDEO_DIP_FREQ_MASK; |
Daniel Vetter | 4b24c93 | 2012-05-08 14:41:00 +0200 | [diff] [blame] | 284 | val |= VIDEO_DIP_FREQ_VSYNC; |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 285 | |
Paulo Zanoni | 22509ec | 2012-05-04 17:18:17 -0300 | [diff] [blame] | 286 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 287 | POSTING_READ(reg); |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 290 | static void hsw_write_infoframe(struct drm_encoder *encoder, |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 291 | struct dip_infoframe *frame) |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 292 | { |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 293 | uint32_t *data = (uint32_t *)frame; |
| 294 | struct drm_device *dev = encoder->dev; |
| 295 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 296 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
Rodrigo Vivi | 7d9bceb | 2013-02-25 19:55:16 -0300 | [diff] [blame] | 297 | u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->cpu_transcoder); |
| 298 | u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->cpu_transcoder); |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 299 | unsigned int i, len = DIP_HEADER_SIZE + frame->len; |
| 300 | u32 val = I915_READ(ctl_reg); |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 301 | |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 302 | if (data_reg == 0) |
| 303 | return; |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 304 | |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 305 | val &= ~hsw_infoframe_enable(frame); |
| 306 | I915_WRITE(ctl_reg, val); |
| 307 | |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 308 | mmiowb(); |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 309 | for (i = 0; i < len; i += 4) { |
| 310 | I915_WRITE(data_reg + i, *data); |
| 311 | data++; |
| 312 | } |
Paulo Zanoni | adf00b2 | 2012-09-25 13:23:34 -0300 | [diff] [blame] | 313 | /* Write every possible data byte to force correct ECC calculation. */ |
| 314 | for (; i < VIDEO_DIP_DATA_SIZE; i += 4) |
| 315 | I915_WRITE(data_reg + i, 0); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 316 | mmiowb(); |
Paulo Zanoni | 2da8af5 | 2012-05-14 17:12:51 -0300 | [diff] [blame] | 317 | |
| 318 | val |= hsw_infoframe_enable(frame); |
| 319 | I915_WRITE(ctl_reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 320 | POSTING_READ(ctl_reg); |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 321 | } |
| 322 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 323 | static void intel_set_infoframe(struct drm_encoder *encoder, |
| 324 | struct dip_infoframe *frame) |
| 325 | { |
| 326 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 327 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 328 | intel_dip_infoframe_csum(frame); |
| 329 | intel_hdmi->write_infoframe(encoder, frame); |
| 330 | } |
| 331 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 332 | static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder, |
Paulo Zanoni | c846b61 | 2012-04-13 16:31:41 -0300 | [diff] [blame] | 333 | struct drm_display_mode *adjusted_mode) |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 334 | { |
Ville Syrjälä | abedc07 | 2013-01-17 16:31:31 +0200 | [diff] [blame] | 335 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 336 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 337 | struct dip_infoframe avi_if = { |
| 338 | .type = DIP_TYPE_AVI, |
| 339 | .ver = DIP_VERSION_AVI, |
| 340 | .len = DIP_LEN_AVI, |
| 341 | }; |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 342 | |
Paulo Zanoni | c846b61 | 2012-04-13 16:31:41 -0300 | [diff] [blame] | 343 | if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 344 | avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2; |
| 345 | |
Ville Syrjälä | abedc07 | 2013-01-17 16:31:31 +0200 | [diff] [blame] | 346 | if (intel_hdmi->rgb_quant_range_selectable) { |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 347 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | abedc07 | 2013-01-17 16:31:31 +0200 | [diff] [blame] | 348 | avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_LIMITED; |
| 349 | else |
| 350 | avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_FULL; |
| 351 | } |
| 352 | |
Thierry Reding | 18316c8 | 2012-12-20 15:41:44 +0100 | [diff] [blame] | 353 | avi_if.body.avi.VIC = drm_match_cea_mode(adjusted_mode); |
Paulo Zanoni | 9a69b88 | 2012-11-23 12:09:27 -0200 | [diff] [blame] | 354 | |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 355 | intel_set_infoframe(encoder, &avi_if); |
Jesse Barnes | b055c8f | 2011-07-08 11:31:57 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 358 | static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder) |
Jesse Barnes | c0864cb | 2011-08-03 09:22:56 -0700 | [diff] [blame] | 359 | { |
| 360 | struct dip_infoframe spd_if; |
| 361 | |
| 362 | memset(&spd_if, 0, sizeof(spd_if)); |
| 363 | spd_if.type = DIP_TYPE_SPD; |
| 364 | spd_if.ver = DIP_VERSION_SPD; |
| 365 | spd_if.len = DIP_LEN_SPD; |
| 366 | strcpy(spd_if.body.spd.vn, "Intel"); |
| 367 | strcpy(spd_if.body.spd.pd, "Integrated gfx"); |
| 368 | spd_if.body.spd.sdi = DIP_SPD_PC; |
| 369 | |
| 370 | intel_set_infoframe(encoder, &spd_if); |
| 371 | } |
| 372 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 373 | static void g4x_set_infoframes(struct drm_encoder *encoder, |
| 374 | struct drm_display_mode *adjusted_mode) |
| 375 | { |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 376 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
Ville Syrjälä | 69fde0a | 2013-01-24 15:29:26 +0200 | [diff] [blame] | 377 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 378 | struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi; |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 379 | u32 reg = VIDEO_DIP_CTL; |
| 380 | u32 val = I915_READ(reg); |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 381 | u32 port; |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 382 | |
Daniel Vetter | afba018 | 2012-06-12 16:36:45 +0200 | [diff] [blame] | 383 | assert_hdmi_port_disabled(intel_hdmi); |
| 384 | |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 385 | /* If the registers were not initialized yet, they might be zeroes, |
| 386 | * which means we're selecting the AVI DIP and we're setting its |
| 387 | * frequency to once. This seems to really confuse the HW and make |
| 388 | * things stop working (the register spec says the AVI always needs to |
| 389 | * be sent every VSync). So here we avoid writing to the register more |
| 390 | * than we need and also explicitly select the AVI DIP and explicitly |
| 391 | * set its frequency to every VSync. Avoiding to write it twice seems to |
| 392 | * be enough to solve the problem, but being defensive shouldn't hurt us |
| 393 | * either. */ |
| 394 | val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC; |
| 395 | |
| 396 | if (!intel_hdmi->has_hdmi_sink) { |
| 397 | if (!(val & VIDEO_DIP_ENABLE)) |
| 398 | return; |
| 399 | val &= ~VIDEO_DIP_ENABLE; |
| 400 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 401 | POSTING_READ(reg); |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 402 | return; |
| 403 | } |
| 404 | |
Ville Syrjälä | 69fde0a | 2013-01-24 15:29:26 +0200 | [diff] [blame] | 405 | switch (intel_dig_port->port) { |
| 406 | case PORT_B: |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 407 | port = VIDEO_DIP_PORT_B; |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 408 | break; |
Ville Syrjälä | 69fde0a | 2013-01-24 15:29:26 +0200 | [diff] [blame] | 409 | case PORT_C: |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 410 | port = VIDEO_DIP_PORT_C; |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 411 | break; |
| 412 | default: |
Paulo Zanoni | 57df2ae | 2012-09-24 10:32:54 -0300 | [diff] [blame] | 413 | BUG(); |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 414 | return; |
| 415 | } |
| 416 | |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 417 | if (port != (val & VIDEO_DIP_PORT_MASK)) { |
| 418 | if (val & VIDEO_DIP_ENABLE) { |
| 419 | val &= ~VIDEO_DIP_ENABLE; |
| 420 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 421 | POSTING_READ(reg); |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 422 | } |
| 423 | val &= ~VIDEO_DIP_PORT_MASK; |
| 424 | val |= port; |
| 425 | } |
| 426 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 427 | val |= VIDEO_DIP_ENABLE; |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 428 | val &= ~VIDEO_DIP_ENABLE_VENDOR; |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 429 | |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 430 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 431 | POSTING_READ(reg); |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 432 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 433 | intel_hdmi_set_avi_infoframe(encoder, adjusted_mode); |
| 434 | intel_hdmi_set_spd_infoframe(encoder); |
| 435 | } |
| 436 | |
| 437 | static void ibx_set_infoframes(struct drm_encoder *encoder, |
| 438 | struct drm_display_mode *adjusted_mode) |
| 439 | { |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 440 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
| 441 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
Ville Syrjälä | 69fde0a | 2013-01-24 15:29:26 +0200 | [diff] [blame] | 442 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 443 | struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi; |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 444 | u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 445 | u32 val = I915_READ(reg); |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 446 | u32 port; |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 447 | |
Daniel Vetter | afba018 | 2012-06-12 16:36:45 +0200 | [diff] [blame] | 448 | assert_hdmi_port_disabled(intel_hdmi); |
| 449 | |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 450 | /* See the big comment in g4x_set_infoframes() */ |
| 451 | val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC; |
| 452 | |
| 453 | if (!intel_hdmi->has_hdmi_sink) { |
| 454 | if (!(val & VIDEO_DIP_ENABLE)) |
| 455 | return; |
| 456 | val &= ~VIDEO_DIP_ENABLE; |
| 457 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 458 | POSTING_READ(reg); |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 459 | return; |
| 460 | } |
| 461 | |
Ville Syrjälä | 69fde0a | 2013-01-24 15:29:26 +0200 | [diff] [blame] | 462 | switch (intel_dig_port->port) { |
| 463 | case PORT_B: |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 464 | port = VIDEO_DIP_PORT_B; |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 465 | break; |
Ville Syrjälä | 69fde0a | 2013-01-24 15:29:26 +0200 | [diff] [blame] | 466 | case PORT_C: |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 467 | port = VIDEO_DIP_PORT_C; |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 468 | break; |
Ville Syrjälä | 69fde0a | 2013-01-24 15:29:26 +0200 | [diff] [blame] | 469 | case PORT_D: |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 470 | port = VIDEO_DIP_PORT_D; |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 471 | break; |
| 472 | default: |
Paulo Zanoni | 57df2ae | 2012-09-24 10:32:54 -0300 | [diff] [blame] | 473 | BUG(); |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 474 | return; |
| 475 | } |
| 476 | |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 477 | if (port != (val & VIDEO_DIP_PORT_MASK)) { |
| 478 | if (val & VIDEO_DIP_ENABLE) { |
| 479 | val &= ~VIDEO_DIP_ENABLE; |
| 480 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 481 | POSTING_READ(reg); |
Paulo Zanoni | 72b78c9 | 2012-05-28 16:42:54 -0300 | [diff] [blame] | 482 | } |
| 483 | val &= ~VIDEO_DIP_PORT_MASK; |
| 484 | val |= port; |
| 485 | } |
| 486 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 487 | val |= VIDEO_DIP_ENABLE; |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 488 | val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT | |
| 489 | VIDEO_DIP_ENABLE_GCP); |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 490 | |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 491 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 492 | POSTING_READ(reg); |
Paulo Zanoni | f278d97 | 2012-05-28 16:42:50 -0300 | [diff] [blame] | 493 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 494 | intel_hdmi_set_avi_infoframe(encoder, adjusted_mode); |
| 495 | intel_hdmi_set_spd_infoframe(encoder); |
| 496 | } |
| 497 | |
| 498 | static void cpt_set_infoframes(struct drm_encoder *encoder, |
| 499 | struct drm_display_mode *adjusted_mode) |
| 500 | { |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 501 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
| 502 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
| 503 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 504 | u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 505 | u32 val = I915_READ(reg); |
| 506 | |
Daniel Vetter | afba018 | 2012-06-12 16:36:45 +0200 | [diff] [blame] | 507 | assert_hdmi_port_disabled(intel_hdmi); |
| 508 | |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 509 | /* See the big comment in g4x_set_infoframes() */ |
| 510 | val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC; |
| 511 | |
| 512 | if (!intel_hdmi->has_hdmi_sink) { |
| 513 | if (!(val & VIDEO_DIP_ENABLE)) |
| 514 | return; |
| 515 | val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI); |
| 516 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 517 | POSTING_READ(reg); |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 518 | return; |
| 519 | } |
| 520 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 521 | /* Set both together, unset both together: see the spec. */ |
| 522 | val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI; |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 523 | val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT | |
| 524 | VIDEO_DIP_ENABLE_GCP); |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 525 | |
| 526 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 527 | POSTING_READ(reg); |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 528 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 529 | intel_hdmi_set_avi_infoframe(encoder, adjusted_mode); |
| 530 | intel_hdmi_set_spd_infoframe(encoder); |
| 531 | } |
| 532 | |
| 533 | static void vlv_set_infoframes(struct drm_encoder *encoder, |
| 534 | struct drm_display_mode *adjusted_mode) |
| 535 | { |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 536 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
| 537 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
| 538 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 539 | u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe); |
| 540 | u32 val = I915_READ(reg); |
| 541 | |
Daniel Vetter | afba018 | 2012-06-12 16:36:45 +0200 | [diff] [blame] | 542 | assert_hdmi_port_disabled(intel_hdmi); |
| 543 | |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 544 | /* See the big comment in g4x_set_infoframes() */ |
| 545 | val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC; |
| 546 | |
| 547 | if (!intel_hdmi->has_hdmi_sink) { |
| 548 | if (!(val & VIDEO_DIP_ENABLE)) |
| 549 | return; |
| 550 | val &= ~VIDEO_DIP_ENABLE; |
| 551 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 552 | POSTING_READ(reg); |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 553 | return; |
| 554 | } |
| 555 | |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 556 | val |= VIDEO_DIP_ENABLE; |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 557 | val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT | |
| 558 | VIDEO_DIP_ENABLE_GCP); |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 559 | |
| 560 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 561 | POSTING_READ(reg); |
Paulo Zanoni | 822974a | 2012-05-28 16:42:51 -0300 | [diff] [blame] | 562 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 563 | intel_hdmi_set_avi_infoframe(encoder, adjusted_mode); |
| 564 | intel_hdmi_set_spd_infoframe(encoder); |
| 565 | } |
| 566 | |
| 567 | static void hsw_set_infoframes(struct drm_encoder *encoder, |
| 568 | struct drm_display_mode *adjusted_mode) |
| 569 | { |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 570 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
| 571 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
| 572 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Rodrigo Vivi | 7d9bceb | 2013-02-25 19:55:16 -0300 | [diff] [blame] | 573 | u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->cpu_transcoder); |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 574 | u32 val = I915_READ(reg); |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 575 | |
Daniel Vetter | afba018 | 2012-06-12 16:36:45 +0200 | [diff] [blame] | 576 | assert_hdmi_port_disabled(intel_hdmi); |
| 577 | |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 578 | if (!intel_hdmi->has_hdmi_sink) { |
| 579 | I915_WRITE(reg, 0); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 580 | POSTING_READ(reg); |
Paulo Zanoni | 0c14c7f | 2012-05-28 16:42:49 -0300 | [diff] [blame] | 581 | return; |
| 582 | } |
| 583 | |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 584 | val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW | |
| 585 | VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW); |
| 586 | |
| 587 | I915_WRITE(reg, val); |
Paulo Zanoni | 9d9740f | 2012-05-28 16:43:00 -0300 | [diff] [blame] | 588 | POSTING_READ(reg); |
Paulo Zanoni | 0dd87d2 | 2012-05-28 16:42:53 -0300 | [diff] [blame] | 589 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 590 | intel_hdmi_set_avi_infoframe(encoder, adjusted_mode); |
| 591 | intel_hdmi_set_spd_infoframe(encoder); |
| 592 | } |
| 593 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 594 | static void intel_hdmi_mode_set(struct drm_encoder *encoder, |
| 595 | struct drm_display_mode *mode, |
| 596 | struct drm_display_mode *adjusted_mode) |
| 597 | { |
| 598 | struct drm_device *dev = encoder->dev; |
| 599 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 600 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 601 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 602 | u32 hdmi_val; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 603 | |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 604 | hdmi_val = SDVO_ENCODING_HDMI; |
Jesse Barnes | 5d4fac9 | 2011-06-24 12:19:19 -0700 | [diff] [blame] | 605 | if (!HAS_PCH_SPLIT(dev)) |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 606 | hdmi_val |= intel_hdmi->color_range; |
Adam Jackson | b599c0b | 2010-07-16 14:46:31 -0400 | [diff] [blame] | 607 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 608 | hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH; |
Adam Jackson | b599c0b | 2010-07-16 14:46:31 -0400 | [diff] [blame] | 609 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 610 | hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 611 | |
Daniel Vetter | 965e0c4 | 2013-03-27 00:44:57 +0100 | [diff] [blame] | 612 | if (intel_crtc->config.pipe_bpp > 24) |
Paulo Zanoni | 4f3a8bc | 2013-02-19 16:21:47 -0300 | [diff] [blame] | 613 | hdmi_val |= HDMI_COLOR_FORMAT_12bpc; |
Jesse Barnes | 020f670 | 2011-06-24 12:19:25 -0700 | [diff] [blame] | 614 | else |
Paulo Zanoni | 4f3a8bc | 2013-02-19 16:21:47 -0300 | [diff] [blame] | 615 | hdmi_val |= SDVO_COLOR_FORMAT_8bpc; |
Jesse Barnes | 020f670 | 2011-06-24 12:19:25 -0700 | [diff] [blame] | 616 | |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 617 | /* Required on CPT */ |
| 618 | if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev)) |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 619 | hdmi_val |= HDMI_MODE_SELECT_HDMI; |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 620 | |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 621 | if (intel_hdmi->has_audio) { |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 622 | DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n", |
| 623 | pipe_name(intel_crtc->pipe)); |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 624 | hdmi_val |= SDVO_AUDIO_ENABLE; |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 625 | hdmi_val |= HDMI_MODE_SELECT_HDMI; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 626 | intel_write_eld(encoder, adjusted_mode); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 627 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 628 | |
Jesse Barnes | 7577056 | 2011-10-12 09:01:58 -0700 | [diff] [blame] | 629 | if (HAS_PCH_CPT(dev)) |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 630 | hdmi_val |= SDVO_PIPE_SEL_CPT(intel_crtc->pipe); |
| 631 | else |
| 632 | hdmi_val |= SDVO_PIPE_SEL(intel_crtc->pipe); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 633 | |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 634 | I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val); |
| 635 | POSTING_READ(intel_hdmi->hdmi_reg); |
David Härdeman | 3c17fe4 | 2010-09-24 21:44:32 +0200 | [diff] [blame] | 636 | |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 637 | intel_hdmi->set_infoframes(encoder, adjusted_mode); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 638 | } |
| 639 | |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 640 | static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder, |
| 641 | enum pipe *pipe) |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 642 | { |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 643 | struct drm_device *dev = encoder->base.dev; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 644 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 645 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); |
| 646 | u32 tmp; |
| 647 | |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 648 | tmp = I915_READ(intel_hdmi->hdmi_reg); |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 649 | |
| 650 | if (!(tmp & SDVO_ENABLE)) |
| 651 | return false; |
| 652 | |
| 653 | if (HAS_PCH_CPT(dev)) |
| 654 | *pipe = PORT_TO_PIPE_CPT(tmp); |
| 655 | else |
| 656 | *pipe = PORT_TO_PIPE(tmp); |
| 657 | |
| 658 | return true; |
| 659 | } |
| 660 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 661 | static void intel_enable_hdmi(struct intel_encoder *encoder) |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 662 | { |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 663 | struct drm_device *dev = encoder->base.dev; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 664 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 665 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 666 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 667 | u32 temp; |
Wu Fengguang | 2deed76 | 2011-12-09 20:42:20 +0800 | [diff] [blame] | 668 | u32 enable_bits = SDVO_ENABLE; |
| 669 | |
| 670 | if (intel_hdmi->has_audio) |
| 671 | enable_bits |= SDVO_AUDIO_ENABLE; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 672 | |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 673 | temp = I915_READ(intel_hdmi->hdmi_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 674 | |
Daniel Vetter | 7a87c28 | 2012-06-05 11:03:39 +0200 | [diff] [blame] | 675 | /* HW workaround for IBX, we need to move the port to transcoder A |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 676 | * before disabling it, so restore the transcoder select bit here. */ |
| 677 | if (HAS_PCH_IBX(dev)) |
| 678 | enable_bits |= SDVO_PIPE_SEL(intel_crtc->pipe); |
Daniel Vetter | 7a87c28 | 2012-06-05 11:03:39 +0200 | [diff] [blame] | 679 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 680 | /* HW workaround, need to toggle enable bit off and on for 12bpc, but |
| 681 | * we do this anyway which shows more stable in testing. |
| 682 | */ |
| 683 | if (HAS_PCH_SPLIT(dev)) { |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 684 | I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE); |
| 685 | POSTING_READ(intel_hdmi->hdmi_reg); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 686 | } |
Daniel Vetter | 7a87c28 | 2012-06-05 11:03:39 +0200 | [diff] [blame] | 687 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 688 | temp |= enable_bits; |
| 689 | |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 690 | I915_WRITE(intel_hdmi->hdmi_reg, temp); |
| 691 | POSTING_READ(intel_hdmi->hdmi_reg); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 692 | |
| 693 | /* HW workaround, need to write this twice for issue that may result |
| 694 | * in first write getting masked. |
| 695 | */ |
| 696 | if (HAS_PCH_SPLIT(dev)) { |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 697 | I915_WRITE(intel_hdmi->hdmi_reg, temp); |
| 698 | POSTING_READ(intel_hdmi->hdmi_reg); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | |
| 702 | static void intel_disable_hdmi(struct intel_encoder *encoder) |
| 703 | { |
| 704 | struct drm_device *dev = encoder->base.dev; |
| 705 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 706 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); |
| 707 | u32 temp; |
Wang Xingchao | 3cce574 | 2012-09-13 11:19:00 +0800 | [diff] [blame] | 708 | u32 enable_bits = SDVO_ENABLE | SDVO_AUDIO_ENABLE; |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 709 | |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 710 | temp = I915_READ(intel_hdmi->hdmi_reg); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 711 | |
| 712 | /* HW workaround for IBX, we need to move the port to transcoder A |
| 713 | * before disabling it. */ |
| 714 | if (HAS_PCH_IBX(dev)) { |
| 715 | struct drm_crtc *crtc = encoder->base.crtc; |
| 716 | int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1; |
| 717 | |
| 718 | if (temp & SDVO_PIPE_B_SELECT) { |
| 719 | temp &= ~SDVO_PIPE_B_SELECT; |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 720 | I915_WRITE(intel_hdmi->hdmi_reg, temp); |
| 721 | POSTING_READ(intel_hdmi->hdmi_reg); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 722 | |
| 723 | /* Again we need to write this twice. */ |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 724 | I915_WRITE(intel_hdmi->hdmi_reg, temp); |
| 725 | POSTING_READ(intel_hdmi->hdmi_reg); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 726 | |
| 727 | /* Transcoder selection bits only update |
| 728 | * effectively on vblank. */ |
| 729 | if (crtc) |
| 730 | intel_wait_for_vblank(dev, pipe); |
| 731 | else |
| 732 | msleep(50); |
Daniel Vetter | 7a87c28 | 2012-06-05 11:03:39 +0200 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 736 | /* HW workaround, need to toggle enable bit off and on for 12bpc, but |
| 737 | * we do this anyway which shows more stable in testing. |
| 738 | */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 739 | if (HAS_PCH_SPLIT(dev)) { |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 740 | I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE); |
| 741 | POSTING_READ(intel_hdmi->hdmi_reg); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 742 | } |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 743 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 744 | temp &= ~enable_bits; |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 745 | |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 746 | I915_WRITE(intel_hdmi->hdmi_reg, temp); |
| 747 | POSTING_READ(intel_hdmi->hdmi_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 748 | |
| 749 | /* HW workaround, need to write this twice for issue that may result |
| 750 | * in first write getting masked. |
| 751 | */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 752 | if (HAS_PCH_SPLIT(dev)) { |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 753 | I915_WRITE(intel_hdmi->hdmi_reg, temp); |
| 754 | POSTING_READ(intel_hdmi->hdmi_reg); |
Zhenyu Wang | d8a2d0e | 2009-11-02 07:52:30 +0000 | [diff] [blame] | 755 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 756 | } |
| 757 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 758 | static int intel_hdmi_mode_valid(struct drm_connector *connector, |
| 759 | struct drm_display_mode *mode) |
| 760 | { |
| 761 | if (mode->clock > 165000) |
| 762 | return MODE_CLOCK_HIGH; |
| 763 | if (mode->clock < 20000) |
Nicolas Kaiser | 5cbba41 | 2011-05-30 12:48:26 +0200 | [diff] [blame] | 764 | return MODE_CLOCK_LOW; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 765 | |
| 766 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 767 | return MODE_NO_DBLESCAN; |
| 768 | |
| 769 | return MODE_OK; |
| 770 | } |
| 771 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 772 | bool intel_hdmi_compute_config(struct intel_encoder *encoder, |
| 773 | struct intel_crtc_config *pipe_config) |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 774 | { |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 775 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); |
| 776 | struct drm_device *dev = encoder->base.dev; |
| 777 | struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 778 | |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 779 | if (intel_hdmi->color_range_auto) { |
| 780 | /* See CEA-861-E - 5.1 Default Encoding Parameters */ |
| 781 | if (intel_hdmi->has_hdmi_sink && |
Thierry Reding | 18316c8 | 2012-12-20 15:41:44 +0100 | [diff] [blame] | 782 | drm_match_cea_mode(adjusted_mode) > 1) |
Paulo Zanoni | 4f3a8bc | 2013-02-19 16:21:47 -0300 | [diff] [blame] | 783 | intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 784 | else |
| 785 | intel_hdmi->color_range = 0; |
| 786 | } |
| 787 | |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 788 | if (intel_hdmi->color_range) |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 789 | pipe_config->limited_color_range = true; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 790 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 791 | if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev)) |
| 792 | pipe_config->has_pch_encoder = true; |
| 793 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 794 | /* |
| 795 | * HDMI is either 12 or 8, so if the display lets 10bpc sneak |
| 796 | * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi |
| 797 | * outputs. |
| 798 | */ |
| 799 | if (pipe_config->pipe_bpp > 8*3 && HAS_PCH_SPLIT(dev)) { |
| 800 | DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n"); |
| 801 | pipe_config->pipe_bpp = 12*3; |
| 802 | } else { |
| 803 | DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n"); |
| 804 | pipe_config->pipe_bpp = 8*3; |
| 805 | } |
| 806 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 807 | return true; |
| 808 | } |
| 809 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 810 | static enum drm_connector_status |
Chris Wilson | 930a9e2 | 2010-09-14 11:07:23 +0100 | [diff] [blame] | 811 | intel_hdmi_detect(struct drm_connector *connector, bool force) |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 812 | { |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 813 | struct drm_device *dev = connector->dev; |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 814 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Paulo Zanoni | d63885d | 2012-10-26 19:05:49 -0200 | [diff] [blame] | 815 | struct intel_digital_port *intel_dig_port = |
| 816 | hdmi_to_dig_port(intel_hdmi); |
| 817 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 818 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 819 | struct edid *edid; |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 820 | enum drm_connector_status status = connector_status_disconnected; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 821 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 822 | intel_hdmi->has_hdmi_sink = false; |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 823 | intel_hdmi->has_audio = false; |
Ville Syrjälä | abedc07 | 2013-01-17 16:31:31 +0200 | [diff] [blame] | 824 | intel_hdmi->rgb_quant_range_selectable = false; |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 825 | edid = drm_get_edid(connector, |
Daniel Kurtz | 3bd7d90 | 2012-03-28 02:36:14 +0800 | [diff] [blame] | 826 | intel_gmbus_get_adapter(dev_priv, |
| 827 | intel_hdmi->ddc_bus)); |
ling.ma@intel.com | 2ded9e2 | 2009-07-16 17:23:09 +0800 | [diff] [blame] | 828 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 829 | if (edid) { |
Eric Anholt | be9f1c4 | 2009-06-21 22:14:55 -0700 | [diff] [blame] | 830 | if (edid->input & DRM_EDID_INPUT_DIGITAL) { |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 831 | status = connector_status_connected; |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 832 | if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI) |
| 833 | intel_hdmi->has_hdmi_sink = |
| 834 | drm_detect_hdmi_monitor(edid); |
Zhenyu Wang | 2e3d600 | 2010-09-10 10:39:40 +0800 | [diff] [blame] | 835 | intel_hdmi->has_audio = drm_detect_monitor_audio(edid); |
Ville Syrjälä | abedc07 | 2013-01-17 16:31:31 +0200 | [diff] [blame] | 836 | intel_hdmi->rgb_quant_range_selectable = |
| 837 | drm_rgb_quant_range_selectable(edid); |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 838 | } |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 839 | kfree(edid); |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 840 | } |
ling.ma@intel.com | 2ded9e2 | 2009-07-16 17:23:09 +0800 | [diff] [blame] | 841 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 842 | if (status == connector_status_connected) { |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 843 | if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO) |
| 844 | intel_hdmi->has_audio = |
| 845 | (intel_hdmi->force_audio == HDMI_AUDIO_ON); |
Paulo Zanoni | d63885d | 2012-10-26 19:05:49 -0200 | [diff] [blame] | 846 | intel_encoder->type = INTEL_OUTPUT_HDMI; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 847 | } |
| 848 | |
Keith Packard | aa93d63 | 2009-05-05 09:52:46 -0700 | [diff] [blame] | 849 | return status; |
Ma Ling | 9dff6af | 2009-04-02 13:13:26 +0800 | [diff] [blame] | 850 | } |
| 851 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 852 | static int intel_hdmi_get_modes(struct drm_connector *connector) |
| 853 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 854 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 855 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 856 | |
| 857 | /* We should parse the EDID data and find out if it's an HDMI sink so |
| 858 | * we can send audio to it. |
| 859 | */ |
| 860 | |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 861 | return intel_ddc_get_modes(connector, |
Daniel Kurtz | 3bd7d90 | 2012-03-28 02:36:14 +0800 | [diff] [blame] | 862 | intel_gmbus_get_adapter(dev_priv, |
| 863 | intel_hdmi->ddc_bus)); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 864 | } |
| 865 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 866 | static bool |
| 867 | intel_hdmi_detect_audio(struct drm_connector *connector) |
| 868 | { |
| 869 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
| 870 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 871 | struct edid *edid; |
| 872 | bool has_audio = false; |
| 873 | |
| 874 | edid = drm_get_edid(connector, |
Daniel Kurtz | 3bd7d90 | 2012-03-28 02:36:14 +0800 | [diff] [blame] | 875 | intel_gmbus_get_adapter(dev_priv, |
| 876 | intel_hdmi->ddc_bus)); |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 877 | if (edid) { |
| 878 | if (edid->input & DRM_EDID_INPUT_DIGITAL) |
| 879 | has_audio = drm_detect_monitor_audio(edid); |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 880 | kfree(edid); |
| 881 | } |
| 882 | |
| 883 | return has_audio; |
| 884 | } |
| 885 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 886 | static int |
| 887 | intel_hdmi_set_property(struct drm_connector *connector, |
Paulo Zanoni | ed517fb | 2012-05-14 17:12:50 -0300 | [diff] [blame] | 888 | struct drm_property *property, |
| 889 | uint64_t val) |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 890 | { |
| 891 | struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector); |
Paulo Zanoni | da63a9f | 2012-10-26 19:05:46 -0200 | [diff] [blame] | 892 | struct intel_digital_port *intel_dig_port = |
| 893 | hdmi_to_dig_port(intel_hdmi); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 894 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 895 | int ret; |
| 896 | |
Rob Clark | 662595d | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 897 | ret = drm_object_property_set_value(&connector->base, property, val); |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 898 | if (ret) |
| 899 | return ret; |
| 900 | |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 901 | if (property == dev_priv->force_audio_property) { |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 902 | enum hdmi_force_audio i = val; |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 903 | bool has_audio; |
| 904 | |
| 905 | if (i == intel_hdmi->force_audio) |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 906 | return 0; |
| 907 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 908 | intel_hdmi->force_audio = i; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 909 | |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 910 | if (i == HDMI_AUDIO_AUTO) |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 911 | has_audio = intel_hdmi_detect_audio(connector); |
| 912 | else |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 913 | has_audio = (i == HDMI_AUDIO_ON); |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 914 | |
Wu Fengguang | b1d7e4b | 2012-02-14 11:45:36 +0800 | [diff] [blame] | 915 | if (i == HDMI_AUDIO_OFF_DVI) |
| 916 | intel_hdmi->has_hdmi_sink = 0; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 917 | |
Chris Wilson | 1aad7ac | 2011-02-09 18:46:58 +0000 | [diff] [blame] | 918 | intel_hdmi->has_audio = has_audio; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 919 | goto done; |
| 920 | } |
| 921 | |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 922 | if (property == dev_priv->broadcast_rgb_property) { |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 923 | switch (val) { |
| 924 | case INTEL_BROADCAST_RGB_AUTO: |
| 925 | intel_hdmi->color_range_auto = true; |
| 926 | break; |
| 927 | case INTEL_BROADCAST_RGB_FULL: |
| 928 | intel_hdmi->color_range_auto = false; |
| 929 | intel_hdmi->color_range = 0; |
| 930 | break; |
| 931 | case INTEL_BROADCAST_RGB_LIMITED: |
| 932 | intel_hdmi->color_range_auto = false; |
Paulo Zanoni | 4f3a8bc | 2013-02-19 16:21:47 -0300 | [diff] [blame] | 933 | intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235; |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 934 | break; |
| 935 | default: |
| 936 | return -EINVAL; |
| 937 | } |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 938 | goto done; |
| 939 | } |
| 940 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 941 | return -EINVAL; |
| 942 | |
| 943 | done: |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 944 | if (intel_dig_port->base.base.crtc) |
| 945 | intel_crtc_restore_mode(intel_dig_port->base.base.crtc); |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 946 | |
| 947 | return 0; |
| 948 | } |
| 949 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 950 | static void intel_hdmi_destroy(struct drm_connector *connector) |
| 951 | { |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 952 | drm_sysfs_connector_remove(connector); |
| 953 | drm_connector_cleanup(connector); |
Zhenyu Wang | 674e2d0 | 2010-03-29 15:57:42 +0800 | [diff] [blame] | 954 | kfree(connector); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = { |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 958 | .mode_set = intel_hdmi_mode_set, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 959 | }; |
| 960 | |
| 961 | static const struct drm_connector_funcs intel_hdmi_connector_funcs = { |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 962 | .dpms = intel_connector_dpms, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 963 | .detect = intel_hdmi_detect, |
| 964 | .fill_modes = drm_helper_probe_single_connector_modes, |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 965 | .set_property = intel_hdmi_set_property, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 966 | .destroy = intel_hdmi_destroy, |
| 967 | }; |
| 968 | |
| 969 | static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = { |
| 970 | .get_modes = intel_hdmi_get_modes, |
| 971 | .mode_valid = intel_hdmi_mode_valid, |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 972 | .best_encoder = intel_best_encoder, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 973 | }; |
| 974 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 975 | static const struct drm_encoder_funcs intel_hdmi_enc_funcs = { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 976 | .destroy = intel_encoder_destroy, |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 977 | }; |
| 978 | |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 979 | static void |
| 980 | intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector) |
| 981 | { |
Chris Wilson | 3f43c48 | 2011-05-12 22:17:24 +0100 | [diff] [blame] | 982 | intel_attach_force_audio_property(connector); |
Chris Wilson | e953fd7 | 2011-02-21 22:23:52 +0000 | [diff] [blame] | 983 | intel_attach_broadcast_rgb_property(connector); |
Ville Syrjälä | 55bc60d | 2013-01-17 16:31:29 +0200 | [diff] [blame] | 984 | intel_hdmi->color_range_auto = true; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 985 | } |
| 986 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 987 | void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port, |
| 988 | struct intel_connector *intel_connector) |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 989 | { |
Paulo Zanoni | b9cb234 | 2012-10-26 19:05:47 -0200 | [diff] [blame] | 990 | struct drm_connector *connector = &intel_connector->base; |
| 991 | struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi; |
| 992 | struct intel_encoder *intel_encoder = &intel_dig_port->base; |
| 993 | struct drm_device *dev = intel_encoder->base.dev; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 994 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 995 | enum port port = intel_dig_port->port; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 996 | |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 997 | drm_connector_init(dev, connector, &intel_hdmi_connector_funcs, |
Adam Jackson | 8d91104 | 2009-09-23 15:08:29 -0400 | [diff] [blame] | 998 | DRM_MODE_CONNECTOR_HDMIA); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 999 | drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs); |
| 1000 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1001 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
Peter Ross | c3febcc | 2012-01-28 14:49:26 +0100 | [diff] [blame] | 1002 | connector->interlace_allowed = 1; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 1003 | connector->doublescan_allowed = 0; |
| 1004 | |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 1005 | switch (port) { |
| 1006 | case PORT_B: |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 1007 | intel_hdmi->ddc_bus = GMBUS_PORT_DPB; |
Egbert Eich | 1d843f9 | 2013-02-25 12:06:49 -0500 | [diff] [blame] | 1008 | intel_encoder->hpd_pin = HPD_PORT_B; |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 1009 | break; |
| 1010 | case PORT_C: |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 1011 | intel_hdmi->ddc_bus = GMBUS_PORT_DPC; |
Egbert Eich | 1d843f9 | 2013-02-25 12:06:49 -0500 | [diff] [blame] | 1012 | intel_encoder->hpd_pin = HPD_PORT_C; |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 1013 | break; |
| 1014 | case PORT_D: |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 1015 | intel_hdmi->ddc_bus = GMBUS_PORT_DPD; |
Egbert Eich | 1d843f9 | 2013-02-25 12:06:49 -0500 | [diff] [blame] | 1016 | intel_encoder->hpd_pin = HPD_PORT_D; |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 1017 | break; |
| 1018 | case PORT_A: |
Egbert Eich | 1d843f9 | 2013-02-25 12:06:49 -0500 | [diff] [blame] | 1019 | intel_encoder->hpd_pin = HPD_PORT_A; |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 1020 | /* Internal port only for eDP. */ |
| 1021 | default: |
Eugeni Dodonov | 6e4c167 | 2012-05-09 15:37:13 -0300 | [diff] [blame] | 1022 | BUG(); |
Ma Ling | f8aed70 | 2009-08-24 13:50:24 +0800 | [diff] [blame] | 1023 | } |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 1024 | |
Jesse Barnes | 7637bfd | 2013-03-08 10:46:01 -0800 | [diff] [blame] | 1025 | if (IS_VALLEYVIEW(dev)) { |
Shobhit Kumar | 90b107c | 2012-03-28 13:39:32 -0700 | [diff] [blame] | 1026 | intel_hdmi->write_infoframe = vlv_write_infoframe; |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 1027 | intel_hdmi->set_infoframes = vlv_set_infoframes; |
Jesse Barnes | 7637bfd | 2013-03-08 10:46:01 -0800 | [diff] [blame] | 1028 | } else if (!HAS_PCH_SPLIT(dev)) { |
| 1029 | intel_hdmi->write_infoframe = g4x_write_infoframe; |
| 1030 | intel_hdmi->set_infoframes = g4x_set_infoframes; |
Paulo Zanoni | 22b8bf1 | 2013-02-18 19:00:23 -0300 | [diff] [blame] | 1031 | } else if (HAS_DDI(dev)) { |
Eugeni Dodonov | 8c5f5f7 | 2012-05-10 10:18:02 -0300 | [diff] [blame] | 1032 | intel_hdmi->write_infoframe = hsw_write_infoframe; |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 1033 | intel_hdmi->set_infoframes = hsw_set_infoframes; |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 1034 | } else if (HAS_PCH_IBX(dev)) { |
| 1035 | intel_hdmi->write_infoframe = ibx_write_infoframe; |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 1036 | intel_hdmi->set_infoframes = ibx_set_infoframes; |
Paulo Zanoni | fdf1250 | 2012-05-04 17:18:24 -0300 | [diff] [blame] | 1037 | } else { |
| 1038 | intel_hdmi->write_infoframe = cpt_write_infoframe; |
Paulo Zanoni | 687f4d0 | 2012-05-28 16:42:48 -0300 | [diff] [blame] | 1039 | intel_hdmi->set_infoframes = cpt_set_infoframes; |
Jesse Barnes | 64a8fc0 | 2011-09-22 11:16:00 +0530 | [diff] [blame] | 1040 | } |
Jesse Barnes | 45187ac | 2011-08-03 09:22:55 -0700 | [diff] [blame] | 1041 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1042 | if (HAS_DDI(dev)) |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1043 | intel_connector->get_hw_state = intel_ddi_connector_get_hw_state; |
| 1044 | else |
| 1045 | intel_connector->get_hw_state = intel_connector_get_hw_state; |
Paulo Zanoni | b9cb234 | 2012-10-26 19:05:47 -0200 | [diff] [blame] | 1046 | |
| 1047 | intel_hdmi_add_properties(intel_hdmi, connector); |
| 1048 | |
| 1049 | intel_connector_attach_encoder(intel_connector, intel_encoder); |
| 1050 | drm_sysfs_connector_add(connector); |
| 1051 | |
| 1052 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written |
| 1053 | * 0xd. Failure to do so will result in spurious interrupts being |
| 1054 | * generated on the port when a cable is not attached. |
| 1055 | */ |
| 1056 | if (IS_G4X(dev) && !IS_GM45(dev)) { |
| 1057 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); |
| 1058 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); |
| 1059 | } |
| 1060 | } |
| 1061 | |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 1062 | void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port) |
Paulo Zanoni | b9cb234 | 2012-10-26 19:05:47 -0200 | [diff] [blame] | 1063 | { |
| 1064 | struct intel_digital_port *intel_dig_port; |
| 1065 | struct intel_encoder *intel_encoder; |
| 1066 | struct drm_encoder *encoder; |
| 1067 | struct intel_connector *intel_connector; |
| 1068 | |
| 1069 | intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL); |
| 1070 | if (!intel_dig_port) |
| 1071 | return; |
| 1072 | |
| 1073 | intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); |
| 1074 | if (!intel_connector) { |
| 1075 | kfree(intel_dig_port); |
| 1076 | return; |
| 1077 | } |
| 1078 | |
| 1079 | intel_encoder = &intel_dig_port->base; |
| 1080 | encoder = &intel_encoder->base; |
| 1081 | |
| 1082 | drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs, |
| 1083 | DRM_MODE_ENCODER_TMDS); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1084 | drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs); |
| 1085 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1086 | intel_encoder->compute_config = intel_hdmi_compute_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1087 | intel_encoder->enable = intel_enable_hdmi; |
| 1088 | intel_encoder->disable = intel_disable_hdmi; |
| 1089 | intel_encoder->get_hw_state = intel_hdmi_get_hw_state; |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 1090 | |
Paulo Zanoni | b9cb234 | 2012-10-26 19:05:47 -0200 | [diff] [blame] | 1091 | intel_encoder->type = INTEL_OUTPUT_HDMI; |
| 1092 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
| 1093 | intel_encoder->cloneable = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 1094 | |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1095 | intel_dig_port->port = port; |
Paulo Zanoni | b242b7f | 2013-02-18 19:00:26 -0300 | [diff] [blame] | 1096 | intel_dig_port->hdmi.hdmi_reg = hdmi_reg; |
Paulo Zanoni | b9cb234 | 2012-10-26 19:05:47 -0200 | [diff] [blame] | 1097 | intel_dig_port->dp.output_reg = 0; |
Chris Wilson | 55b7d6e8 | 2010-09-19 09:29:33 +0100 | [diff] [blame] | 1098 | |
Paulo Zanoni | b9cb234 | 2012-10-26 19:05:47 -0200 | [diff] [blame] | 1099 | intel_hdmi_init_connector(intel_dig_port, intel_connector); |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 1100 | } |