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