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