]>
Commit | Line | Data |
---|---|---|
7d57382e EA |
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> | |
30 | #include <linux/delay.h> | |
31 | #include "drmP.h" | |
32 | #include "drm.h" | |
33 | #include "drm_crtc.h" | |
aa93d632 | 34 | #include "drm_edid.h" |
7d57382e EA |
35 | #include "intel_drv.h" |
36 | #include "i915_drm.h" | |
37 | #include "i915_drv.h" | |
38 | ||
39 | struct intel_hdmi_priv { | |
40 | u32 sdvox_reg; | |
41 | u32 save_SDVOX; | |
9dff6af8 | 42 | bool has_hdmi_sink; |
7d57382e EA |
43 | }; |
44 | ||
45 | static void intel_hdmi_mode_set(struct drm_encoder *encoder, | |
46 | struct drm_display_mode *mode, | |
47 | struct drm_display_mode *adjusted_mode) | |
48 | { | |
49 | struct drm_device *dev = encoder->dev; | |
50 | struct drm_i915_private *dev_priv = dev->dev_private; | |
51 | struct drm_crtc *crtc = encoder->crtc; | |
52 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); | |
53 | struct intel_output *intel_output = enc_to_intel_output(encoder); | |
54 | struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv; | |
55 | u32 sdvox; | |
56 | ||
57 | sdvox = SDVO_ENCODING_HDMI | | |
58 | SDVO_BORDER_ENABLE | | |
59 | SDVO_VSYNC_ACTIVE_HIGH | | |
56d21b07 | 60 | SDVO_HSYNC_ACTIVE_HIGH; |
7d57382e EA |
61 | |
62 | if (hdmi_priv->has_hdmi_sink) | |
63 | sdvox |= SDVO_AUDIO_ENABLE; | |
64 | ||
65 | if (intel_crtc->pipe == 1) | |
66 | sdvox |= SDVO_PIPE_B_SELECT; | |
67 | ||
68 | I915_WRITE(hdmi_priv->sdvox_reg, sdvox); | |
69 | POSTING_READ(hdmi_priv->sdvox_reg); | |
70 | } | |
71 | ||
72 | static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode) | |
73 | { | |
74 | struct drm_device *dev = encoder->dev; | |
75 | struct drm_i915_private *dev_priv = dev->dev_private; | |
76 | struct intel_output *intel_output = enc_to_intel_output(encoder); | |
77 | struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv; | |
78 | u32 temp; | |
79 | ||
d8a2d0e0 ZW |
80 | temp = I915_READ(hdmi_priv->sdvox_reg); |
81 | ||
82 | /* HW workaround, need to toggle enable bit off and on for 12bpc, but | |
83 | * we do this anyway which shows more stable in testing. | |
84 | */ | |
c619eed4 | 85 | if (HAS_PCH_SPLIT(dev)) { |
7d57382e | 86 | I915_WRITE(hdmi_priv->sdvox_reg, temp & ~SDVO_ENABLE); |
d8a2d0e0 ZW |
87 | POSTING_READ(hdmi_priv->sdvox_reg); |
88 | } | |
89 | ||
90 | if (mode != DRM_MODE_DPMS_ON) { | |
91 | temp &= ~SDVO_ENABLE; | |
7d57382e | 92 | } else { |
d8a2d0e0 | 93 | temp |= SDVO_ENABLE; |
7d57382e | 94 | } |
d8a2d0e0 ZW |
95 | |
96 | I915_WRITE(hdmi_priv->sdvox_reg, temp); | |
7d57382e | 97 | POSTING_READ(hdmi_priv->sdvox_reg); |
d8a2d0e0 ZW |
98 | |
99 | /* HW workaround, need to write this twice for issue that may result | |
100 | * in first write getting masked. | |
101 | */ | |
c619eed4 | 102 | if (HAS_PCH_SPLIT(dev)) { |
d8a2d0e0 ZW |
103 | I915_WRITE(hdmi_priv->sdvox_reg, temp); |
104 | POSTING_READ(hdmi_priv->sdvox_reg); | |
105 | } | |
7d57382e EA |
106 | } |
107 | ||
108 | static void intel_hdmi_save(struct drm_connector *connector) | |
109 | { | |
110 | struct drm_device *dev = connector->dev; | |
111 | struct drm_i915_private *dev_priv = dev->dev_private; | |
112 | struct intel_output *intel_output = to_intel_output(connector); | |
113 | struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv; | |
114 | ||
115 | hdmi_priv->save_SDVOX = I915_READ(hdmi_priv->sdvox_reg); | |
116 | } | |
117 | ||
118 | static void intel_hdmi_restore(struct drm_connector *connector) | |
119 | { | |
120 | struct drm_device *dev = connector->dev; | |
121 | struct drm_i915_private *dev_priv = dev->dev_private; | |
122 | struct intel_output *intel_output = to_intel_output(connector); | |
123 | struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv; | |
124 | ||
125 | I915_WRITE(hdmi_priv->sdvox_reg, hdmi_priv->save_SDVOX); | |
126 | POSTING_READ(hdmi_priv->sdvox_reg); | |
127 | } | |
128 | ||
129 | static int intel_hdmi_mode_valid(struct drm_connector *connector, | |
130 | struct drm_display_mode *mode) | |
131 | { | |
132 | if (mode->clock > 165000) | |
133 | return MODE_CLOCK_HIGH; | |
134 | if (mode->clock < 20000) | |
135 | return MODE_CLOCK_HIGH; | |
136 | ||
137 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) | |
138 | return MODE_NO_DBLESCAN; | |
139 | ||
140 | return MODE_OK; | |
141 | } | |
142 | ||
143 | static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder, | |
144 | struct drm_display_mode *mode, | |
145 | struct drm_display_mode *adjusted_mode) | |
146 | { | |
147 | return true; | |
148 | } | |
149 | ||
aa93d632 | 150 | static enum drm_connector_status |
2ded9e27 | 151 | intel_hdmi_detect(struct drm_connector *connector) |
9dff6af8 ML |
152 | { |
153 | struct intel_output *intel_output = to_intel_output(connector); | |
154 | struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv; | |
155 | struct edid *edid = NULL; | |
aa93d632 | 156 | enum drm_connector_status status = connector_status_disconnected; |
9dff6af8 | 157 | |
2ded9e27 | 158 | hdmi_priv->has_hdmi_sink = false; |
9dff6af8 | 159 | edid = drm_get_edid(&intel_output->base, |
f9c10a9b | 160 | intel_output->ddc_bus); |
2ded9e27 | 161 | |
aa93d632 | 162 | if (edid) { |
be9f1c4f | 163 | if (edid->input & DRM_EDID_INPUT_DIGITAL) { |
aa93d632 KP |
164 | status = connector_status_connected; |
165 | hdmi_priv->has_hdmi_sink = drm_detect_hdmi_monitor(edid); | |
166 | } | |
9dff6af8 | 167 | intel_output->base.display_info.raw_edid = NULL; |
aa93d632 | 168 | kfree(edid); |
9dff6af8 | 169 | } |
30ad48b7 | 170 | |
2ded9e27 | 171 | return status; |
7d57382e EA |
172 | } |
173 | ||
174 | static int intel_hdmi_get_modes(struct drm_connector *connector) | |
175 | { | |
176 | struct intel_output *intel_output = to_intel_output(connector); | |
177 | ||
178 | /* We should parse the EDID data and find out if it's an HDMI sink so | |
179 | * we can send audio to it. | |
180 | */ | |
181 | ||
182 | return intel_ddc_get_modes(intel_output); | |
183 | } | |
184 | ||
185 | static void intel_hdmi_destroy(struct drm_connector *connector) | |
186 | { | |
187 | struct intel_output *intel_output = to_intel_output(connector); | |
188 | ||
189 | if (intel_output->i2c_bus) | |
190 | intel_i2c_destroy(intel_output->i2c_bus); | |
191 | drm_sysfs_connector_remove(connector); | |
192 | drm_connector_cleanup(connector); | |
193 | kfree(intel_output); | |
194 | } | |
195 | ||
196 | static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = { | |
197 | .dpms = intel_hdmi_dpms, | |
198 | .mode_fixup = intel_hdmi_mode_fixup, | |
199 | .prepare = intel_encoder_prepare, | |
200 | .mode_set = intel_hdmi_mode_set, | |
201 | .commit = intel_encoder_commit, | |
202 | }; | |
203 | ||
204 | static const struct drm_connector_funcs intel_hdmi_connector_funcs = { | |
c9fb15f6 | 205 | .dpms = drm_helper_connector_dpms, |
7d57382e EA |
206 | .save = intel_hdmi_save, |
207 | .restore = intel_hdmi_restore, | |
208 | .detect = intel_hdmi_detect, | |
209 | .fill_modes = drm_helper_probe_single_connector_modes, | |
210 | .destroy = intel_hdmi_destroy, | |
211 | }; | |
212 | ||
213 | static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = { | |
214 | .get_modes = intel_hdmi_get_modes, | |
215 | .mode_valid = intel_hdmi_mode_valid, | |
216 | .best_encoder = intel_best_encoder, | |
217 | }; | |
218 | ||
219 | static void intel_hdmi_enc_destroy(struct drm_encoder *encoder) | |
220 | { | |
221 | drm_encoder_cleanup(encoder); | |
222 | } | |
223 | ||
224 | static const struct drm_encoder_funcs intel_hdmi_enc_funcs = { | |
225 | .destroy = intel_hdmi_enc_destroy, | |
226 | }; | |
227 | ||
7d57382e EA |
228 | void intel_hdmi_init(struct drm_device *dev, int sdvox_reg) |
229 | { | |
230 | struct drm_i915_private *dev_priv = dev->dev_private; | |
231 | struct drm_connector *connector; | |
232 | struct intel_output *intel_output; | |
233 | struct intel_hdmi_priv *hdmi_priv; | |
234 | ||
235 | intel_output = kcalloc(sizeof(struct intel_output) + | |
236 | sizeof(struct intel_hdmi_priv), 1, GFP_KERNEL); | |
237 | if (!intel_output) | |
238 | return; | |
239 | hdmi_priv = (struct intel_hdmi_priv *)(intel_output + 1); | |
240 | ||
241 | connector = &intel_output->base; | |
242 | drm_connector_init(dev, connector, &intel_hdmi_connector_funcs, | |
8d91104a | 243 | DRM_MODE_CONNECTOR_HDMIA); |
7d57382e EA |
244 | drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs); |
245 | ||
246 | intel_output->type = INTEL_OUTPUT_HDMI; | |
247 | ||
248 | connector->interlace_allowed = 0; | |
249 | connector->doublescan_allowed = 0; | |
f8aed700 | 250 | intel_output->crtc_mask = (1 << 0) | (1 << 1); |
7d57382e EA |
251 | |
252 | /* Set up the DDC bus. */ | |
f8aed700 ML |
253 | if (sdvox_reg == SDVOB) { |
254 | intel_output->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT); | |
7d57382e | 255 | intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "HDMIB"); |
b01f2c3a | 256 | dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; |
f8aed700 ML |
257 | } else if (sdvox_reg == SDVOC) { |
258 | intel_output->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT); | |
7d57382e | 259 | intel_output->ddc_bus = intel_i2c_create(dev, GPIOD, "HDMIC"); |
b01f2c3a | 260 | dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; |
f8aed700 ML |
261 | } else if (sdvox_reg == HDMIB) { |
262 | intel_output->clone_mask = (1 << INTEL_HDMID_CLONE_BIT); | |
30ad48b7 ZW |
263 | intel_output->ddc_bus = intel_i2c_create(dev, PCH_GPIOE, |
264 | "HDMIB"); | |
b01f2c3a | 265 | dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; |
f8aed700 ML |
266 | } else if (sdvox_reg == HDMIC) { |
267 | intel_output->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT); | |
30ad48b7 ZW |
268 | intel_output->ddc_bus = intel_i2c_create(dev, PCH_GPIOD, |
269 | "HDMIC"); | |
b01f2c3a | 270 | dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; |
f8aed700 ML |
271 | } else if (sdvox_reg == HDMID) { |
272 | intel_output->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT); | |
30ad48b7 ZW |
273 | intel_output->ddc_bus = intel_i2c_create(dev, PCH_GPIOF, |
274 | "HDMID"); | |
b01f2c3a | 275 | dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS; |
f8aed700 | 276 | } |
7d57382e EA |
277 | if (!intel_output->ddc_bus) |
278 | goto err_connector; | |
279 | ||
280 | hdmi_priv->sdvox_reg = sdvox_reg; | |
281 | intel_output->dev_priv = hdmi_priv; | |
282 | ||
283 | drm_encoder_init(dev, &intel_output->enc, &intel_hdmi_enc_funcs, | |
284 | DRM_MODE_ENCODER_TMDS); | |
285 | drm_encoder_helper_add(&intel_output->enc, &intel_hdmi_helper_funcs); | |
286 | ||
287 | drm_mode_connector_attach_encoder(&intel_output->base, | |
288 | &intel_output->enc); | |
289 | drm_sysfs_connector_add(connector); | |
290 | ||
291 | /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written | |
292 | * 0xd. Failure to do so will result in spurious interrupts being | |
293 | * generated on the port when a cable is not attached. | |
294 | */ | |
295 | if (IS_G4X(dev) && !IS_GM45(dev)) { | |
296 | u32 temp = I915_READ(PEG_BAND_GAP_DATA); | |
297 | I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd); | |
298 | } | |
299 | ||
300 | return; | |
301 | ||
302 | err_connector: | |
303 | drm_connector_cleanup(connector); | |
304 | kfree(intel_output); | |
305 | ||
306 | return; | |
307 | } |